#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main(void)
{
int t;
cin >> t;
while (t--)
{
string arr;
stack <char> s;
bool flag = false;
cin >> arr;
for (char c : arr)
{
if (c == '(') s.push('(');
else if (s.empty())
{
flag = true;
cout << "NO" << endl;
break;
}
else s.pop();
}
if (!flag)
{
if (s.empty()) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3RhY2s+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4odm9pZCkKewoJaW50IHQ7CgljaW4gPj4gdDsKCXdoaWxlICh0LS0pCgl7CgkJc3RyaW5nIGFycjsKCQlzdGFjayA8Y2hhcj4gczsKCQlib29sIGZsYWcgPSBmYWxzZTsKCQljaW4gPj4gYXJyOwoKCQlmb3IgKGNoYXIgYyA6IGFycikKCQl7CgkJCWlmIChjID09ICcoJykgcy5wdXNoKCcoJyk7CgkJCWVsc2UgaWYgKHMuZW1wdHkoKSkKCQkJewoJCQkJZmxhZyA9IHRydWU7CgkJCQljb3V0IDw8ICJOTyIgPDwgZW5kbDsKCQkJCWJyZWFrOwoJCQl9CgkJCWVsc2Ugcy5wb3AoKTsKCQl9CgkJaWYgKCFmbGFnKQoJCXsKCQkJaWYgKHMuZW1wdHkoKSkgY291dCA8PCAiWUVTIiA8PCBlbmRsOwoJCQllbHNlIGNvdXQgPDwgIk5PIiA8PCBlbmRsOwoJCX0KCX0KCXJldHVybiAwOwp9