#include<iostream>
#include<cstdio>
#include<stack>
#define maxn 130
using namespace std;
int main(){
int n,flag=1;
cin>>n;
getchar();
char tmp[maxn];
stack<char>s;
while(n--){
flag=1;
while(!s.empty()) s.pop();
gets(tmp);
for(int i=0;tmp[i]!='\0';i++){
if(tmp[i]=='['||tmp[i]=='(')
s.push(tmp[i]);
if(tmp[i]==']'){
if(!s.empty()&&s.top()=='[')
s.pop();
else {
cout<<"No"<<"\n";
flag=0;
break;
}
}
if(tmp[i]==')'){
if(!s.empty()&&s.top()=='(')
s.pop();
else {
cout<<"No"<<"\n";
flag=0;
break;
}
}
}
if(flag){
if(s.empty())cout<<"Yes"<<"\n";
}
}
}