//
// main.cpp
// Copyright © 2016年 Ernest. All rights reserved.
//
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> s;
int main() {
int n;
while(cin>>n){
s.clear();
int t = n;
char temp[130];
char c;
c = getchar();
while(t--){
cin.getline(temp, 130);
s.push_back(temp);
}
for (auto it = s.begin(); it!=s.end(); ++it) {
bool state = true;
int ql,qr,pl,pr;
ql=qr=pl=pr = 0;
for (auto is = it->begin(); is!=it->end(); ++is) {
switch (*is) {
case'[':
++ql;
break;
case']':
++qr;
break;
case'(':
++pl;
break;
case')':
++pr;
break;
default:
break;
}
if(pl<pr || ql<qr)
state = false;
}
if(ql==qr && pl==pr && state)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return0;
}