#include <iostream>
#include <stack>
#include <unordered_map>
using namespace std;
bool isValid(string s);
int main(){
int n;
cin >> n;
string str[n];
for(int i = 0;i < n;i++){
cin >> str[i];
}
for(int i = 0;i < n;i++){
if(isValid(str[i])){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
}
bool isValid(string s)
{
int n = s.size();
if (n % 2 == 1)
{
return false;
}
unordered_map<char, char> pairs = {
{')', '('},
{']', '['},
{'}', '{'}};
stack<char> stk;
for (char ch : s)
{
if (pairs.count(ch))
{
if (stk.empty() || stk.top() != pairs[ch])
{
return false;
}
stk.pop();
}
else
{
stk.push(ch);
}
}
return stk.empty();
}
兄弟,你的图片都不清楚