9012
#include <stdio.h>
#include <string.h>
int main(void){
// 테스트 케이스 입력
int test_case = 0;
scanf("%d", &test_case);
getchar(); // 버퍼 비우기
for(int i = 0; i < test_case; i++){
// 괄호 문자열(Parenthesis String, PS) 입력
char ps [51] = {0};
scanf("%s", &ps);
int len = strlen(ps);
int count = 0;
for(int j = 0; j < len; j++){
if(ps[j] == '('){ // 시작 괄호면 +1
count++;
}
else if(ps[j] == ')'){ // 끝 괄호면 -1
count--;
}
// 만약 카운트가 음수일 경우 break;
if(count < 0){
break;
}
}
// count가 0이면 VPS가 맞으므로 YES 출력
if(!count){
printf("YES\n");
}
// count가 0이 아닌 수면 VPS가 아니여서 NO 출력
else{
printf("NO\n");
}
}
return 0;
}