#include <bits/stdc++.h>
using namespace std;
const int MaxSize=100;
typedef char ElemType;
typedef struct SqStack{
ElemType data[MaxSize];
int top;
}Stack;
void init(Stack *&s)
{
s=(Stack *)malloc(sizeof(Stack));
s->top=-1;
}
bool push(Stack *&s,ElemType e)
{
if(s->top==MaxSize-1) return false;
s->top++;
s->data[s->top]=e;
return true;
}
bool pop(Stack *&s,ElemType &e)
{
if(s->top==-1) return false;
e=s->data[s->top];
s->top--;
return true;
}
bool slove(string s,Stack *&l){
char e;
for(int j=0;j<(int)
s.length ();j++){
char a=s[j];
if(a == '[' || a == '{' || a == '(')push(l,a);
else if(a == ']' && l->data[l->top] == '['){
if (!pop(l, e)) return false;}
else if(a == '}' && l->data[l->top] == '{'){
if (!pop(l, e)) return false;}
else if (a == ')' && l->data[l->top] == '('){
if (!pop(l, e)) return false;}
else if(a==']'||a=='}'||a==')')return false;
} return true;
}
int main(){
int n;
cin>>n;
while(n--){
Stack *l;
init(l);
string s;
cin>>s;
if(slove(s,l)&&l->top==-1)cout<<"yes"<<endl;
else cout<<"no"<<endl;
}}