#include <bits/stdc++.h>
using namespace std;
bool isVPS(string s) {
int depth = 0;
for(long unsigned int i=0; i<s.length(); i++) {
char ch = s[i];
if( ch == '(' ) depth++;
else depth--;
if( depth < 0 ) return false;
}
if( depth != 0 ) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while(T--) {
string s;
cin >> s;
cout << (isVPS(s) ? "YES\n" : "NO\n");
}
}
import java.util.Scanner;
public class Main {
static boolean is_vps(String str) {
int depth = 0;
for(int i=0; i<str.length(); i++) {
char ch = str.charAt(i);
if( ch == '(' ) depth++;
else depth--;
if( depth < 0 ) return false;
}
if( depth != 0 ) return false;
return true;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=0; i<n; i++) {
System.out.println( is_vps(sc.next()) ? "YES" : "NO" );
}
}
}