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

string str;
int p;
int solve(int i,int j,int k){
    int sum=0,ok=1;
    for(int ii=0;ii<str.length();ii++){
        if(str[ii]=='A')sum+=i;
        if(str[ii]=='B')sum+=j;
        if(str[ii]=='C')sum+=k;
        if(sum<0){ok=0;break;}
    }
    if(ok&&sum==0)p=1;
    
}
int main(){
	int n;
	scanf("%d",&n);
	for(int iI=1;iI<=n;iI++){
		cin>>str;
		p=0;
		for(int i=-1;i<2;i+=2)
            for(int j=-1;j<2;j+=2)
                for(int k=-1;k<2;k+=2){
                    if(i==j&&j==k&&i==k)continue;
                    solve(i,j,k);
                    if(p)break;
                }
        if(p)cout<<"YES\n";
        else cout<<"NO\n";
	}
}
