#include <stdio.h>
int main() {
int n = 0;
scanf("%d", &n);
for(int i=0; i<n; i++){
char target[51];
scanf("%s", target);
int j = 0;
int count = 0;
while(target[j] != '\0'){
if(target[j] == '(') count++;
else count--;
if(count<0) {
printf("NO\n");
break;
}
j++;
}
if(count == 0) printf("YES\n");
else if(count >= 0) printf("NO\n");
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: