#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin >> t;
	while(t--){
		string s;
		cin >> s;
		int calc_o = 0, calc_c = 0;
		int need_o, need_c;
		for(char c : s){
			if(c == '('){
				calc_o++;
			}else{
				calc_c++;
			}
		}
		int size = s.size();
		if(size & 1){
			cout << "NO\n";
			continue;
		}
		if(calc_o > calc_c){
			need_c = calc_o - calc_c;
			need_o = (size - calc_o - calc_c - need_c) / 2;
			need_c = need_c + need_o;
		}else{
			need_o = calc_c - calc_o;
			need_c = (size - calc_o - calc_c - need_o) / 2;
			need_o = need_c + need_o;
		}
		int cnt = 0;
		bool valid = true;
		for(char c : s){
			if(c == '('){
				cnt++;
			}else if(c == ')'){
				cnt--;
				if(cnt < 0){
					valid = false;
					break;
				}
			}else{
				if(need_o){
					cnt++;
					need_o--;
				}else{
					cnt--;
					need_c--;
					if(cnt < 0){
						valid = false;
						break;
					}
				}
			}
		}
		if(cnt != 0){
			valid = false;
		}
		cout << (valid ? "YES\n" : "NO\n");
	}
}
