#include<bits/stdc++.h>
using namespace std;
stack<char> v;
bool ikun(string s){
while(!v.empty()) v.pop();
for(int i=0;i<s.size();i++){
if(s[i]=='['||s[i]=='('){
v.push(s[i]);
}
else{
if(s[i]==']'){
if(v.top()=='(') return false;
if(v.empty()) return false;
else v.pop();
}
if(s[i]==')'){
if(v.top()=='[') return false;
if(v.empty()) return false;
else v.pop();
}
}
}
if(v.empty()) return true;
else return false;
}
int main(){
int n;
cin>>n;
string a;
for(int i=1;i<=n;i++){
cin>>a;
if(ikun(a)) cout<<"Yes";
else cout<<"No";
cout<<endl;
}
return 0;
}