#include <bits/stdc++.h>

using namespace std;
stack<char> s;
int num;

/**
测试用例:
2
[({})]
()[]()
*/
char trans(char a) {
if (a == ')') return '(';
if (a == ']') return '[';
if (a == '}') return '{';
return '\0';
}

int main() {
cin >> num;
string p;
//getline(cin, p);//读取末尾的指针
getchar();
while (num--) {
while (!s.empty())s.pop();
getline(cin, p);
for (int i = 0; i < p.size(); i++) {
if (s.empty()) {
s.push(p[i]);
continue;
}
if (trans(p[i]) == s.top())s.pop();
else s.push(p[i]);
}
if (s.empty())printf("Yes\n");
else printf("No\n");
}
return 0;
}