#include <bits/stdc++.h>
using namespace std;
int n;
stack <char> s;
char d;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
s.push('!');
getchar();
for (int i = 1; i <= n; i++){
string tmp;
getline(cin, tmp);
int len = tmp.size();
for (int j = 0; j < len; j++){
s.push(tmp[j]);
if (s.top() == ')'){
if (d == '('){
s.pop();
s.pop();
}
} else if (s.top() == ']'){
if (d == '['){
s.pop();
s.pop();
}
}
d = s.top();
}
if (s.top() == '!'){
cout << "Yes\n";
} else {
cout << "No\n";
while (!(s.top() == '!')){
s.pop();
}
}
}
return 0;
}