#include <stdio.h>
int main(void) {
int n, i, top, s;
char t[10001];
while(n--){
top = i = s = 0;
while(t[i]){
if(t[i]==')'){
if(t[top-1]=='('){
top--;
} else {
s = -1;
break;
}
} else if(t[i]=='}'){
if(t[top-1]=='{'){
top--;
} else {
s = -1;
break;
}
} else if(t[i]==']'){
if(t[top-1]=='['){
top--;
} else {
s = -1;
break;
}
} else {
t[top++] = t[i];
}
i++;
}
if(s==0){
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CglpbnQgbiwgaSwgdG9wLCBzOwoJY2hhciB0WzEwMDAxXTsKCglzY2FuZigiJWQiLCAmbik7Cgl3aGlsZShuLS0pewoJCXRvcCA9IGkgPSBzID0gMDsKCQlzY2FuZigiJXMiLCAmdCk7CgkJd2hpbGUodFtpXSl7CgkJCWlmKHRbaV09PScpJyl7CgkJCQlpZih0W3RvcC0xXT09JygnKXsKCQkJCQl0b3AtLTsKCQkJCX0gZWxzZSB7CgkJCQkJcHJpbnRmKCJOT1xuIik7CgkJCQkJcyA9IC0xOwoJCQkJCWJyZWFrOwoJCQkJfQoJCQl9IGVsc2UgaWYodFtpXT09J30nKXsKCQkJCWlmKHRbdG9wLTFdPT0neycpewoJCQkJCXRvcC0tOwoJCQkJfSBlbHNlIHsKCQkJCQlwcmludGYoIk5PXG4iKTsKCQkJCQlzID0gLTE7CgkJCQkJYnJlYWs7CgkJCQl9CgkJCX0gZWxzZSBpZih0W2ldPT0nXScpewoJCQkJaWYodFt0b3AtMV09PSdbJyl7CgkJCQkJdG9wLS07CgkJCQl9IGVsc2UgewoJCQkJCXByaW50ZigiTk9cbiIpOwoJCQkJCXMgPSAtMTsKCQkJCQlicmVhazsKCQkJCX0KCQkJfSBlbHNlIHsKCQkJCXRbdG9wKytdID0gdFtpXTsKCQkJfQoJCQlpKys7CgkJfQoJCWlmKHM9PTApewoJCQlpZih0b3A9PTApIHByaW50ZigiWUVTXG4iKTsKCQkJZWxzZSBwcmludGYoIk5PXG4iKTsKCQl9Cgl9CglyZXR1cm4gMDsKfQ==