#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
int n;
cin>>n;
cin.ignore();
while(n--)
{
string temp;
getline(cin,temp);
if(temp=="")
{
cout<<"Yes"<<endl;
}
else
{
stack<char> s;
int i;
for( i=0;i<temp.length();i++)
{
if(temp[i]=='('||temp[i]=='[')
s.push(temp[i]);
else
{
if(!s.empty())
{
char ch=s.top();
if((temp[i]==')'&&ch=='(')||(temp[i]==']'&&ch=='['))
s.pop();
else
{
s.push(temp[i]);
}
}
else
{
s.push(temp[i]);
}
}
}
if(s.empty())
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return 0;
}