#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector  <vll> vvl;
typedef vector <vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpi;
typedef vector <pll> vpl;
const ll mod = 1000000007;
const int infi = 1e9 + 5;
const ll infl = 4e18;
#define all(v) v.begin(), v.end()
int main()
{
	ll t, n, a1, b1, c1;
	vector <bool> vb = { true,true,true,true,true,true };
	vll a, b, c;
	string s;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> s;
		n = s.size();
		a = {}, b = {}, c = {};
		a1 = 0, b1 = 0, c1 = 0;
		for (char ch : s) {
			if (ch == 'A') a1++;
			else if (ch == 'B') b1++;
			else c1++;
			a.push_back(a1);
			b.push_back(b1);
			c.push_back(c1);
		}
		vb = { true,true,true,true,true,true };
		for (int j = 0; j < n; j++) {
			if (a[j] + b[j] < c[j]) vb[0] = false;
			if (a[j] + c[j] < b[j]) vb[1] = false;
			if (b[j] + c[j] < a[j]) vb[2] = false;
			if (a[j] < b[j] + c[j]) vb[3] = false;
			if (b[j] < a[j] + c[j]) vb[4] = false;
			if (c[j] < b[j] + a[j]) vb[5] = false;
		}
		if ((vb[0] || vb[5]) && c1 == a1 + b1) cout << "YES\n";
		else if ((vb[1] || vb[4]) && b1 == a1 + c1) cout << "YES\n";
		else if ((vb[2] || vb[3]) && a1 == b1 + c1) cout << "YES\n";
		else cout << "NO\n";
	}
}