#include using namespace std; const int nmax=4005; int n,j,i,l; char a[nmax]; stack stiv; int convert (char x) { if (x=='(') return 1; if (x==')') return -1; if (x=='{') return 2; if (x=='}') return -2; if (x=='[') return 3; if (x==']') return -3; if (x=='|') return 0; } void solve() { int ac; bool luat=0; for (i=0;i=0 && luat==0) { stiv.push(ac); } } if (!stiv.empty()) cout<<"NO"<<'\n'; else cout<<"YES"<<'\n'; } int main() { cin>>n; while (n--) { cin>>a; l=strlen(a); solve(); while (!stiv.empty()) stiv.pop(); } } /// too much heresy