#include<bits/stdc++.h>
using namespace std;
stack<char> s;
long long n;
string x;
int main(){
cin>>n;
while(n--){
cin>>x;
for(int i=0;i<x.length();i++){
if(s.empty()){
s.push(x[i]);
continue;
}
if(s.top()=='('&&x[i]==')')s.pop();
else if(s.top()=='['&&x[i]==']')s.pop();
else if(s.top()=='{'&&x[i]=='}')s.pop();
else s.push(x[i]);
}
if(s.empty())cout<<"Yes"<<endl;
else cout<<"No"<<endl;
while(!s.empty())s.pop();
}
return 0;
}