public class BracketStackMine
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();// 3条测试数据数据
Stack<Character> stack = null;
boolean flag = true;
while (n != 0)
{
// 从控制台读入一个测试字符串[]() [(])
String str = sc.next();
// 如果该输入字符串为奇数,说明不匹配
stack = new Stack<Character>();
// 遍历第一条测试字符串[]() [(])
for (int i = 0; i < str.length() && flag; i++)
{
char currentChar = str.charAt(i);
if(currentChar =='(' || currentChar == '['){
stack.push(currentChar);
continue;
}
if(currentChar == ')'){
if(stack.peek() == '('){
stack.pop();
}else{
flag = false;
System.out.println("No");
}
}
if(currentChar == ']'){
if(stack.peek() == '['){
stack.pop();
}else{
flag = false;
System.out.println("No");
}
}
}
if (flag)
{
System.out.println("Yes");
}
flag = true;
n--;
}
}
}
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();// 3条测试数据数据
Stack<Character> stack = null;
boolean flag = true;
while (n != 0)
{
// 从控制台读入一个测试字符串[]() [(])
String str = sc.next();
// 如果该输入字符串为奇数,说明不匹配
stack = new Stack<Character>();
// 遍历第一条测试字符串[]() [(])
for (int i = 0; i < str.length() && flag; i++)
{
char currentChar = str.charAt(i);
if(currentChar =='(' || currentChar == '['){
stack.push(currentChar);
continue;
}
if(currentChar == ')'){
if(stack.peek() == '('){
stack.pop();
}else{
flag = false;
System.out.println("No");
}
}
if(currentChar == ']'){
if(stack.peek() == '['){
stack.pop();
}else{
flag = false;
System.out.println("No");
}
}
}
if (flag)
{
System.out.println("Yes");
}
flag = true;
n--;
}
}
}