#pragma region 라이브러리
#include <iostream>
#include <cmath>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
#pragma endregion
#pragma region 최적화용
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0);
#define x first
#define x second
using IntPair = pair<int, int>;
using DoubleVec = vector<vector<int>>;
using Vec = vector<int>;
// 상하좌우
IntPair dir[]
{
{ 1, 0 },
{-1, 0 },
{ 0, -1 },
{ 0, 1 }
};
#pragma endregion
int main()
{
int t;
cin >> t;
stack<int> s;
while (t--)
{
string str;
cin >> str;
for (int i = 0; i < str.size(); i++)
{
char ch = str[i];
if (s.empty())
s.push(ch);
else
{
if (s.top() == '(' && ch == ')')
s.pop();
else
s.push(ch);
}
}
cout << (s.empty() ? "YES" : "NO") << '\n';
s = stack<int>();
}
return 0;
}