/*简 单 的 栈 问 题 ...1A 水 过~~*/
#include <stdio.h>
#include <string.h>
char str[200];
char stack[300];
int top;
int main()
{
int N, len, i, flag;
scanf( "%d", &N );
getchar();
while( N-- )
{
flag = 1;
top = 0;
gets( str );
len = strlen(str);
for( i = 0; i < len; i++ )
{
if( str[i] == '(' || str[i] == '[' )
{
stack[top++] = str[i];
continue;
}
if( str[i] == ')' || str[i] == ']' )
{
if( str[i] == ')' && stack[top-1] == '(' )
{
top--;
continue;
}
if( str[i] == ']' && stack[top-1] == '[' )
{
top--;
continue;
}
flag = 0;
}
}
if( !top && flag )
printf( "Yes\n" );
else
printf( "No\n" );
}
return 0;
}