import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.utf;

bool isGood (R) (R s)
{
	int balance = 0;
	foreach (c; s)
	{
		balance += c ? +1 : -1;
		if (balance < 0)
		{
			return false;
		}
	}
	return balance == 0;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		bool ok = false;
		foreach (i; 0..8)
		{
			int [char] t;
			t['A'] = (i >> 0) & 1;
			t['B'] = (i >> 1) & 1;
			t['C'] = (i >> 2) & 1;
			ok |= isGood (s.byChar.map !(c => t[c]));
		}
		writeln (ok ? "YES" : "NO");
	}
}
