#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 */
struct stack {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
struct stack *stack_create(int);
int /*<<< orphan*/ stack_delete(struct stack *);
char stack_get_pop(struct stack *);
scalar_t__ stack_is_empty(struct stack *);
int /*<<< orphan*/ stack_pop(struct stack *);
int /*<<< orphan*/ stack_push(struct stack *, char);
int strlen(char *);
int main(int argc, char **argv) {
  int lines;
  char input[10000];
  scanf("%d", &lines);
  getchar();
  while (lines--) {
    gets(input);
    int i, length = strlen(input);
    struct stack *s = stack_create(length);
    for (i = 0; i < length; i++) {
      if (input[i] == '[' || input[i] == '(')
        stack_push(s, input[i]);
      else if (input[i] == ']') {
        if ((!stack_is_empty(s)) && (stack_get_pop(s) == '['))
          stack_pop(s);
        else {
          printf("No\n");
          break;
        }
      } else if (input[i] == ')') {
        if ((!stack_is_empty(s)) && (stack_get_pop(s) == '('))
          stack_pop(s);
        else {
          printf("No\n");
          break;
        }
      } else
        ;
    }
    if (stack_is_empty(s) && i == length)
      printf("Yes\n");
    stack_delete(s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     13d7 <main+0x227>
lea    -0x2730(%rbp),%rdi
call   1090 <gets@plt>
lea    -0x2730(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2738(%rbp)
mov    -0x2738(%rbp),%edi
call   1080 <stack_create@plt>
mov    %rax,-0x2740(%rbp)
movl   $0x0,-0x2734(%rbp)
mov    -0x2734(%rbp),%eax
cmp    -0x2738(%rbp),%eax
jge    1392 <main+0x1e2>
movslq -0x2734(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%eax
ff
cmp    $0x5b,%eax
je     1270 <main+0xc0>
movslq -0x2734(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%eax
ff
cmp    $0x28,%eax
jne    1290 <main+0xe0>
mov    -0x2740(%rbp),%rdi
movslq -0x2734(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%esi
ff
call   10c0 <stack_push@plt>
jmp    1379 <main+0x1c9>
movslq -0x2734(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%eax
ff
cmp    $0x5d,%eax
jne    12fd <main+0x14d>
mov    -0x2740(%rbp),%rdi
call   10b0 <stack_is_empty@plt>
cmp    $0x0,%rax
jne    12e7 <main+0x137>
mov    -0x2740(%rbp),%rdi
call   1030 <stack_get_pop@plt>
movsbl %al,%eax
cmp    $0x5b,%eax
jne    12e7 <main+0x137>
mov    -0x2740(%rbp),%rdi
call   10d0 <stack_pop@plt>
jmp    12f8 <main+0x148>
lea    0xd15(%rip),%rdi
call   1060 <printf@plt>
jmp    1392 <main+0x1e2>
jmp    1374 <main+0x1c4>
movslq -0x2734(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%eax
ff
cmp    $0x29,%eax
jne    136a <main+0x1ba>
mov    -0x2740(%rbp),%rdi
call   10b0 <stack_is_empty@plt>
cmp    $0x0,%rax
jne    1354 <main+0x1a4>
mov    -0x2740(%rbp),%rdi
call   1030 <stack_get_pop@plt>
movsbl %al,%eax
cmp    $0x28,%eax
jne    1354 <main+0x1a4>
mov    -0x2740(%rbp),%rdi
call   10d0 <stack_pop@plt>
jmp    1365 <main+0x1b5>
lea    0xca8(%rip),%rdi
call   1060 <printf@plt>
jmp    1392 <main+0x1e2>
jmp    136f <main+0x1bf>
jmp    136f <main+0x1bf>
jmp    1374 <main+0x1c4>
jmp    1379 <main+0x1c9>
jmp    137e <main+0x1ce>
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2734(%rbp)
jmp    122e <main+0x7e>
mov    -0x2740(%rbp),%rdi
call   10b0 <stack_is_empty@plt>
cmp    $0x0,%rax
je     13c6 <main+0x216>
mov    -0x2734(%rbp),%eax
cmp    -0x2738(%rbp),%eax
jne    13c6 <main+0x216>
lea    0xc46(%rip),%rdi
call   1060 <printf@plt>
mov    -0x2740(%rbp),%rdi
call   1050 <stack_delete@plt>
jmp    11e0 <main+0x30>
xor    %eax,%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2728,%rsp
lea    0xe38(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
subl   $0x1,0xc(%rsp)
jae    11f4 <main+0x44>
xor    %eax,%eax
add    $0x2728,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r12
lea    0xe03(%rip),%r15
jmp    121f <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <stack_delete@plt>
subl   $0x1,0xc(%rsp)
jb     11e0 <main+0x30>
mov    %r12,%rdi
call   1090 <gets@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%r14d
mov    %eax,%edi
call   1080 <stack_create@plt>
mov    %rax,%rbx
mov    $0x0,%r13d
test   %ebp,%ebp
jle    130c <main+0x15c>
xor    %r13d,%r13d
jmp    1274 <main+0xc4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %rbx,%rdi
call   10c0 <stack_push@plt>
add    $0x1,%r13
cmp    %r13,%r14
je     12f0 <main+0x140>
movzbl 0x10(%rsp,%r13,1),%eax
cmp    $0x5a,%al
jg     12b0 <main+0x100>
cmp    $0x28,%al
je     1260 <main+0xb0>
cmp    $0x29,%al
jne    126b <main+0xbb>
mov    %rbx,%rdi
call   10b0 <stack_is_empty@plt>
test   %rax,%rax
jne    1300 <main+0x150>
mov    %rbx,%rdi
call   1030 <stack_get_pop@plt>
cmp    $0x28,%al
je     12d9 <main+0x129>
jmp    1300 <main+0x150>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x5d,%al
je     12c0 <main+0x110>
cmp    $0x5b,%al
je     1260 <main+0xb0>
jmp    126b <main+0xbb>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <stack_is_empty@plt>
test   %rax,%rax
jne    1300 <main+0x150>
mov    %rbx,%rdi
call   1030 <stack_get_pop@plt>
cmp    $0x5b,%al
jne    1300 <main+0x150>
mov    %rbx,%rdi
call   10d0 <stack_pop@plt>
jmp    126b <main+0xbb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,%r13d
jmp    130c <main+0x15c>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xd00(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10b0 <stack_is_empty@plt>
test   %rax,%rax
je     1210 <main+0x60>
cmp    %r14d,%r13d
jne    1210 <main+0x60>
mov    %r15,%rdi
call   1040 <puts@plt>
jmp    1210 <main+0x60>

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

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