#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    bool qnfkf = false;
    vector <string> v(n);
    for (int i = 0;i < n;i++) {
        cin >> v[i];
    }
    for (int i = 0;i < n;i++) {
        int tmp = 0;
        int cnt = 0;
        int cont = 0;
        for (int j = 0;j < v[i].size();j++) {
            if (v[i][j] == '(') {
                qnfkf = true;
                cnt ++;
            }
            else{
                if (qnfkf) {
                    cont++;
                    qnfkf = false;
                }
                else{
                    cout << "NO" << "\n";
                    break;
                    tmp == 1;
                }
            }
        }
        if (!tmp) {
            if (cnt == cont) {
                cout << "YES" << "\n";
            }
            else{
                cout << "NO" << "\n";
            }
        }
        qnfkf = false;
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: