#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) ((x)&(-x))
#define rep(i,a,n) for (ll i=a;i<=n;i++)
#define per(i,a,n) for (ll i=n;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
const ll mod=1e9+7;
const ll N=2e5+5;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll ans=1;a%=mod;while(b>0)
{if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans%mod;}
ll readn(){ll sum=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){sum=sum*10+(ch-'0');
ch=getchar();}return sum*f;}






ll n,a[N],st[N];
string s;
bool check(ll x){
    ll top=0,f=1;
    for(ll i=0;i<x;i++){
        if(a[i]==1)st[++top]=1;
        else{
            if(st[top]==1)top--;
            else return false;
        }
    }
    if(top==0)return true;
    else return false;
}
int main(){
    cin>>n;
    while(n--){
        cin>>s;
        ll f=0,len=s.size();
        rep(i,1,2)
        rep(j,1,2)
        rep(k,1,2){
            for(ll p=0;p<len;p++){
                if(s[p]=='A')a[p]=i;
                if(s[p]=='B')a[p]=j;
                if(s[p]=='C')a[p]=k;
            }
            if(check(len)){f=1;}
        }
        if(f==1)puts("YES");
        else puts("NO");
    }
}