#include <stack>
#include <string>
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t;
cin >> t;
while (t--) {
string str;
cin >> str;
stack<char> st;
for (int i = 0; i < str.length(); ++i) {
if (st.empty()) {
st.push(str[i]);
continue;
}
if (st.top() == '(' && str[i] == ')') st.pop();
else st.push(str[i]);
}
if (st.empty()) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}