#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

int main()
{
    ll t,i,j;
    cin>>t;
    while(t--)
    {
        stack<char> st;
        bool ans=true;
        string s;
        cin>>s;
        if(s.size()%2!=0)
        ans=false;
        if(s[0]==')'||s[s.size()-1]=='(')
        ans=false;
        ll count=0,count1=0,count2=0;
        for(i=0;i<s.size();i++)
        {
            if(s[i]=='(')
            count++;
            else if(s[i]==')')
            {
                count1++;
            }
            else
            count2++;
            if(count1>count2+count)
            ans=false;
        }
        if(count1>count2+count)
        ans=false;
        if(ans)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
}