#include <iostream>
#include <stack>
using namespace std;
#include <bits/stdc++.h>

bool isBalanced(string exp) 
{ 
    // Initialising Variables 
    bool flag = true; 
    int count = 0; 
  
    // Traversing the Expression 
    for (int i = 0; i<exp.size() ; i++) { 
  
        if (exp[i] == '(') { 
            count++; 
        } 
        else { 
            // It is a closing parenthesis 
            count--; 
        } 
        if (count < 0) { 
            // This means there are 
            // more Closing parenthesis 
            // than opening ones 
            flag = false; 
            break; 
        } 
    } 
 
    if (count != 0) { 
        flag = false; 
    } 
  
    return flag; 
} 

int main()
{
    int t;
    cin>>t;
    
    while(t--)
    {
        string s;
        cin>>s;
        int i;
        
        for( i=0 ; i<8 ; i++)
        {
            int n = s.size();
            string s1 = s;
            
            for(int j=0 ; j<n ; j++)
            {
                if(s1[j]=='A')
                    s1[j] = (i&1) ? '(':')';
                
                if(s1[j]=='B')
                    s1[j] = (i&2) ? '(':')';
                    
                if(s1[j]=='C')
                    s1[j] = (i&4) ? '(':')';
            }
            if(isBalanced(s1))
            {       
                cout<<"yes \n";
                break;
            }
        }
        if(i==8)
            cout<<"no \n";
    }
}