#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int strlen(char *);
int main() {
  char input[1005];
  char support[1005];
  int i = 0, point = 1, loop = 0, j = 0;
  scanf("%d", &loop);
  gets(input);
  for (j = 0; j < loop; j++) {
    gets(input);
    support[0] = input[0];
    i = 0, point = 1;
    for (i = 1; i < strlen(input); i++) {
      if (input[i] == ')' && support[point - 1] == '(')
        point--;
      else if (input[i] == ']' && support[point - 1] == '[')
        point--;
      else
        support[point++] = input[i];
    }
    if ((strlen(input)) == 0 || point == 0)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x7f4(%rbp)
movl   $0x1,-0x7f8(%rbp)
movl   $0x0,-0x7fc(%rbp)
movl   $0x0,-0x800(%rbp)
lea    0xe7f(%rip),%rdi
lea    -0x7fc(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x400(%rbp),%rdi
call   1050 <gets@plt>
movl   $0x0,-0x800(%rbp)
mov    -0x800(%rbp),%eax
cmp    -0x7fc(%rbp),%eax
jge    1341 <main+0x201>
lea    -0x400(%rbp),%rdi
call   1050 <gets@plt>
mov    -0x400(%rbp),%al
mov    %al,-0x7f0(%rbp)
movl   $0x0,-0x7f4(%rbp)
movl   $0x1,-0x7f8(%rbp)
movl   $0x1,-0x7f4(%rbp)
mov    -0x7f4(%rbp),%eax
mov    %eax,-0x804(%rbp)
lea    -0x400(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x804(%rbp),%eax
cmp    %ecx,%eax
jge    12e9 <main+0x1a9>
movslq -0x7f4(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x29,%eax
jne    125b <main+0x11b>
mov    -0x7f8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x7f0(%rbp,%rax,1),%eax
ff
cmp    $0x28,%eax
jne    125b <main+0x11b>
mov    -0x7f8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7f8(%rbp)
jmp    12d0 <main+0x190>
movslq -0x7f4(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x5d,%eax
jne    12a3 <main+0x163>
mov    -0x7f8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x7f0(%rbp,%rax,1),%eax
ff
cmp    $0x5b,%eax
jne    12a3 <main+0x163>
mov    -0x7f8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7f8(%rbp)
jmp    12cb <main+0x18b>
movslq -0x7f4(%rbp),%rax
mov    -0x400(%rbp,%rax,1),%cl
mov    -0x7f8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x7f8(%rbp)
cltq
mov    %cl,-0x7f0(%rbp,%rax,1)
jmp    12d0 <main+0x190>
jmp    12d5 <main+0x195>
mov    -0x7f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7f4(%rbp)
jmp    11eb <main+0xab>
lea    -0x400(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
je     130b <main+0x1cb>
cmpl   $0x0,-0x7f8(%rbp)
jne    131c <main+0x1dc>
lea    0xcf1(%rip),%rdi
call   1040 <printf@plt>
jmp    1328 <main+0x1e8>
lea    0xce5(%rip),%rdi
call   1040 <printf@plt>
jmp    132d <main+0x1ed>
mov    -0x800(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x800(%rbp)
jmp    11a3 <main+0x63>
xor    %eax,%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f8,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
lea    0x400(%rsp),%rdi
call   1050 <gets@plt>
cmpl   $0x0,0xc(%rsp)
jle    124f <main+0x10f>
xor    %r12d,%r12d
lea    0x400(%rsp),%r13
lea    0xe72(%rip),%r14
lea    0xe68(%rip),%r15
jmp    11cb <main+0x8b>
nopl   (%rax)
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %ebx,%ebx
mov    %r15,%rdi
cmove  %r14,%rdi
test   %eax,%eax
cmove  %r14,%rdi
call   1030 <puts@plt>
add    $0x1,%r12d
cmp    0xc(%rsp),%r12d
jge    124f <main+0x10f>
mov    %r13,%rdi
call   1050 <gets@plt>
mov    0x400(%rsp),%al
mov    %al,0x10(%rsp)
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    $0x1,%ebx
cmp    $0x2,%eax
jl     11a0 <main+0x60>
mov    $0x1,%ebx
mov    $0x1,%ebp
jmp    121a <main+0xda>
nopl   0x0(%rax)
lea    0x1(%rax),%ebx
mov    %cl,0x10(%rsp,%rax,1)
add    $0x1,%rbp
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    11a0 <main+0x60>
movzbl 0x400(%rsp,%rbp,1),%ecx
movslq %ebx,%rax
cmp    $0x5d,%cl
je     1240 <main+0x100>
cmp    $0x29,%cl
jne    1200 <main+0xc0>
cmpb   $0x28,0xf(%rsp,%rax,1)
jne    1200 <main+0xc0>
jmp    1247 <main+0x107>
nopl   0x0(%rax,%rax,1)
cmpb   $0x5b,0xf(%rsp,%rax,1)
jne    1200 <main+0xc0>
add    $0xffffffffffffffff,%rax
mov    %eax,%ebx
jmp    1207 <main+0xc7>
xor    %eax,%eax
add    $0x7f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"Yes\0A\00"
@.str.2 = [4 x i8] c"No\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1005 x i8]
%3 = alloca [1005 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%9 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
store i32 0, i32* %7
br label %11
11: ; preds = %88, %0
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %91
15: ; preds = %11
%16 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 0
%17 = call i32 @gets(i8* %16)
%18 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 0
%19 = load i8, i8* %18
%20 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 0
store i8 %19, i8* %20
store i32 0, i32* %4
store i32 1, i32* %5
store i32 1, i32* %4
br label %21
21: ; preds = %73, %15
%22 = load i32, i32* %4
%23 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %76
26: ; preds = %21
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 41
br i1 %32, label %33, label %44
33: ; preds = %26
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 40
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* %5
%43 = add nsw i32 %42, -1
store i32 %43, i32* %5
br label %72
44: ; preds = %33, %26
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 93
br i1 %50, label %51, label %62
51: ; preds = %44
%52 = load i32, i32* %5
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 91
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = load i32, i32* %5
%61 = add nsw i32 %60, -1
store i32 %61, i32* %5
br label %71
62: ; preds = %51, %44
%63 = load i32, i32* %4
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
store i32 %68, i32* %5
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 %69
store i8 %66, i8* %70
br label %71
71: ; preds = %62, %59
br label %72
72: ; preds = %71, %41
br label %73
73: ; preds = %72
%74 = load i32, i32* %4
%75 = add nsw i32 %74, 1
store i32 %75, i32* %4
br label %21
76: ; preds = %21
%77 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 0
%78 = call i32 @strlen(i8* %77)
%79 = icmp eq i32 %78, 0
br i1 %79, label %83, label %80
80: ; preds = %76
%81 = load i32, i32* %5
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %80, %76
%84 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %87
85: ; preds = %80
%86 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %87
87: ; preds = %85, %83
br label %88
88: ; preds = %87
%89 = load i32, i32* %7
%90 = add nsw i32 %89, 1
store i32 %90, i32* %7
br label %11
91: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [3 x i8] c"No\00"
@str.3 = [4 x i8] c"Yes\00"
define i32 @main() {
%1 = alloca [1005 x i8]
%2 = alloca [1005 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [1005 x i8], [1005 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = call i32 @gets(i8* %4)
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %55
11: ; preds = %0, %44
%12 = phi i32 [ %52, %44 ], [ 0, %0 ]
%13 = call i32 @gets(i8* %4)
%14 = load i8, i8* %4
store i8 %14, i8* %5
%15 = call i32 @strlen(i8* %4)
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %44
17: ; preds = %11, %38
%18 = phi i64 [ %40, %38 ], [ 1, %11 ]
%19 = phi i32 [ %39, %38 ], [ 1, %11 ]
%20 = getelementptr inbounds [1005 x i8], [1005 x i8]* %1, i64 0, i64 %18
%21 = load i8, i8* %20
switch i8 %21, label %34 [
i8 41, label %22
i8 93, label %28
]
22: ; preds = %17
%23 = add nsw i32 %19, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 40
br i1 %27, label %38, label %34
28: ; preds = %17
%29 = add nsw i32 %19, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 91
br i1 %33, label %38, label %34
34: ; preds = %17, %22, %28
%35 = add nsw i32 %19, 1
%36 = sext i32 %19 to i64
%37 = getelementptr inbounds [1005 x i8], [1005 x i8]* %2, i64 0, i64 %36
store i8 %21, i8* %37
br label %38
38: ; preds = %28, %22, %34
%39 = phi i32 [ %35, %34 ], [ %23, %22 ], [ %29, %28 ]
%40 = add nuw nsw i64 %18, 1
%41 = call i32 @strlen(i8* %4)
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %17, label %44
44: ; preds = %38, %11
%45 = phi i32 [ 1, %11 ], [ %39, %38 ]
%46 = call i32 @strlen(i8* %4)
%47 = icmp eq i32 %46, 0
%48 = icmp eq i32 %45, 0
%49 = select i1 %47, i1 true, i1 %48
%50 = select i1 %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0)
%51 = call i32 @puts(i8* dereferenceable(1) %50)
%52 = add nuw nsw i32 %12, 1
%53 = load i32, i32* %3
%54 = icmp slt i32 %52, %53
br i1 %54, label %11, label %55
55: ; preds = %44, %0
ret i32 0
}