#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string str;
cin >> str;
stack<char> st;
int flag = 1;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '[' || str[i] == '(' || str[i] == '{') {
st.push(str[i]);
}
if (str[i] == ']') {
if (!st.empty()) {
if (st.top() == '[') {
st.pop();
} else {
flag = 0;
}
} else {
flag = 0;
}
}
if (str[i] == ')') {
if (!st.empty()) {
if (st.top() == '(') {
st.pop();
} else {
flag = 0;
}
} else {
flag = 0;
}
}
if (str[i] == '}') {
if (!st.empty()) {
if (st.top() == '{') {
st.pop();
} else {
flag = 0;
}
} else {
flag = 0;
}
}
}
if (flag == 1&&st.empty()) cout << "yes" << endl;
else cout << "no" << endl;
}
return 0;
}

京公网安备 11010502036488号