#include <bits/stdc++.h>

using namespace std;

#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ell unsigned long long int
#define ld long double
#define ar array
#define endl "\n"

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define Ima INT_MAX
#define Imi INT_MIN

#define vvi vector<vector<int>>
#define vvii vector<vector<pii>>
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<long>
#define vii vector<pii>
#define vs vector<string>

#define mi map<int,int>
#define mii map<pii,int>

#define f(i,a,b) for(int i=a; i<b; i++)
#define f0(i,a) for(int i=0; i<a; i++)
#define rf(i,a,b) for(int i=b; i>=a; i--)
#define rf0(i,a) for(int i=a; i>=0; i--)
#define fa(a) for(auto x:a) cout << x << ' ';
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define it(x,a) for(auto x:a)
#define wt(t) while(t--)

#define possibilities(x) while(next_permutation(all(x)))

#define PI 3.1415926535897932384626

const int mxN = 2e6;
const ll mod = 1e9+7;
int t;

void solve() {
	cin >> t;
	wt(t) {
		string a; cin >> a;

		int per[6][3] = {
			{1,1,0},
			{0,1,1},
			{0,0,1},
			{1,0,0},
			{1,0,1},
			{0,1,0},
		};
		bool ans = false;
		f0(i,6) {
			int arr[sz(a)];
			f0(j,sz(a)) {
				if(a[j]=='A') arr[j] = per[i][0];
				if(a[j]=='B') arr[j] = per[i][1];
				if(a[j]=='C') arr[j] = per[i][2];
			}

			int open = 0, close = 0;
			bool flag = false;
			f0(j,sz(a)) {
				if(arr[j]==0) open++;
				if(arr[j]==1) close++;

				if(close>open) {
					flag = true;
					break;
				}
			}

			if(open==close && !flag) {
				ans = true;
				break;
			}
		}
		if(ans) {
			cout << "YES" << endl;
		} else cout << "NO" << endl;
	}
}

int main() {
	FAST;
	solve();
}