#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#define endl "\n"
#define Doura() ios_base::sync_with_stdio(false),cin.tie(NULL), cout.tie(NULL)
#define ll long long
using namespace std;
const long long MXX=1e7;
bool ChkStack(string s)
{
    stack<char>stk;
    for(auto i: s)
    {
        if(i=='(')
            stk.push(i);
        else
        {
            if(stk.empty())
                return false;
            else
            {
                if(i==')'&& stk.top()!='(')
                   return false;
                   stk.pop();
            }
        }
    }
    if(stk.empty()) return true;
    else return false;
}
void kajelag()
{
     string s,bs="";
     int cnt=0;
     bool flag=true;
     cin>>s;
     char a=s[0],b=s.back();
     if(s.size()%2) cout<<"NO"<<endl;
     else if(a!=b)
     {
          for(int i=0;i<s.size();i++)
          {
               if(s[i]==a)
                    bs+="(";
               else if(s[i]==b)
                    bs+=")";
               else bs+="(";
          }
          if(ChkStack(bs))
          {
               cout<<"YES"<<endl;
               return;
          }
          bs="";
          cnt=0,flag=true;
          for(int i=0;i<s.size();i++)
          {
               if(s[i]==a)
                    bs+="(";
               else if(s[i]==b)
                    bs+=")";
               else bs+=")";
          }
          if(ChkStack(bs))
          {
               cout<<"YES"<<endl;
               return;
          }
          cout<<"NO"<<endl;
     }
     else if(a==b) cout<<"NO"<<endl;
}
int main()
{
      #ifndef ONLINE_JUDGE
             freopen("input.txt","r",stdin);
             freopen("output.txt","w",stdout);
     #endif // ONLINE_JUDGE
     Doura();
     int t;
     cin>>t;
     while(t--)
     {
          kajelag();
     }
     return 0;
}
