题目链接
#include <bits/stdc++.h>
using namespace std;
int sb[1000005];
int main() {
int n,nn=0;
cin>>n;
getchar();
string s;
getline(cin,s);
for(int i=1;i<=n;i++){
getline(cin,s);
stack<char>stk;
while(!stk.empty())stk.pop();
int f=1;
int x=s.size();
if(x==0){
f=1;
}
for(int j=0;j<x;j++){
if(s[j]=='('){
stk.push('(');
}else if(s[j]=='[')
{
stk.push('[');
}else if(s[j]==')'){
if(stk.empty()){
f=0;
}
else{
if(stk.top()=='('){
stk.pop();
}else{
f=0;
}
}
}else if(s[j]==']'){
if(stk.empty()){
f=0;
}else{
if(stk.top()=='['){
stk.pop();
}else{
f=0;
}
}
}
}
if(f)sb[nn++]=1;
else sb[nn++]=0;
}
for(int i=0;i<nn;i++){
if(sb[i]==1){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
return 0;
}