#include<iostream>
#include<stack>
#include<vector>
using namespace std;
//用栈进行括号匹配,只对(,[,{,进行压栈,对),],}进行与栈顶的匹配
int main(void)
{
    vector<string> arr;
    int n;
    
    while(cin >> n)
    {
        while(n--)
        {
            string s;
            cin >> s;
            arr.push_back(s);
        }
        
        string s1;
        for(int i =0;i < arr.size();i++)
        {
            stack<char> s;
            s1 = arr[i];//表达式
            char c = s1[0];//存储逐个遍历表达式中的当前字符
            int j = 0;
            bool mark = 0;//标记遍历字符串的过程中是否已经做出判决
            
            while(c != '\0')//遍历表达式
            {
                if(c == '(' || c == '[' || c == '{')
                    s.push(c);
                if(c == ')' && !s.empty())
                {
                    char temp = s.top();
                    if(temp == '(')
                        s.pop();
                    else
                    {
                        cout << "no" << endl;
                        mark = 1;
                        break;
                    }
                }
                else if(c == ')' && s.empty())
                {
                    cout << "no" << endl;
                    mark = 1;
                    break;
                }
                if(c == ']' && !s.empty())
                {
                    char temp = s.top();
                    if(temp == '[')
                        s.pop();
                    else
                    {
                        cout << "no" << endl;
                        mark = 1;
                        break;
                    }
                }
                else if(c == ']' && s.empty())
                {
                    cout << "no" << endl;
                    mark = 1;
                    break;
                }
                if(c == '}' && !s.empty())
                {
                    char temp = s.top();
                    if(temp == '{')
                        s.pop();
                    else
                    {
                        cout << "no" << endl;
                        mark = 1;
                        break;
                    }
                }
                else if(c == '}' && s.empty())
                {
                    cout << "no" << endl;
                    mark = 1;
                    break;
                }
                c = s1[++j];
            }
//遍历完表达式后做出的判决
            if(!s.empty() && mark == 0)
                cout << "no" << endl;
            if(s.empty() && mark == 0)
                cout << "yes" << endl;
        }
    }
    return 0;
}