#include<bits/stdc++.h>
using namespace std;
 
 
#define loop(i,l,n) for(long i=l;i<n;i++)
#define push_back   emplace_back
const int MOD = 1000000007;
 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
 
 
void run()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
	#ifndef ONLINE_JUDGE
		freopen("/home/punit/Documents/Cpp Programs/input.txt","r",stdin);
		freopen("/home/punit/Documents/Cpp Programs/output.txt","w",stdout);
	#endif
}

bool check(string s)
{
	int count=0;
	for(auto x:s)
	{
		if(x==')')
			count--;
		if(x=='(')
			count++;
		if(count<0)
			return false;
	}
	return count==0;
}
int main()
{
	run();
	string arr[7];
	arr[0]="((("; arr[1]="(()";arr[2]="()(";arr[3]="())";arr[4]=")((";arr[5]=")()";arr[6]="))(";

	int test;
	cin>>test;
	while(test--)
	{
		string s;
		cin>>s;
		int flag=0;
		for(int i=0;i<7;i++)
		{
			string temp="";
			for(auto x:s)
			{
				if(x=='A')
					temp+=arr[i][0];
				else if(x=='B')
					temp+=arr[i][1];
				else if(x=='C')
					temp+=arr[i][2];

			}
			// cout<<temp<<" ";
			if(check(temp))
			{
				flag=1;
				break;
			}
		}
		if(flag)
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}

}