#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<string> arr(n);
for (int i = 0;i < n;i++) {
cin >> arr[i];
}
int cnt = 0;
for (int i = 0;i < n;i++) {
stack<char> s;
int b = 0;
for (int j = 0;j < arr[i].size();j++) {
char c = arr[i][j];
s.push(c);
}
while (!s.empty()) {
if (s.top() == '(') {
cnt ++;
s.pop();
}
else{
cnt--;
if (cnt < 0) {
s.pop();
break;
}
else{
s.pop();
}
}
}
if (cnt == 0) {
cout << "YES" << "\n";
}
else{
cout << "NO" << "\n";
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: