#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ull> vll;

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const ull MOD = 1e9+7;

bool is_valid(string& s, char a, char b, char c) {
	int opened = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A') {
			if (a == '(') opened++;
			else opened--;
		}
		if (s[i] == 'B') {
			if (b == '(') opened++;
			else opened--;
		}
		if (s[i] == 'C') {
			if (c == '(') opened++;
			else opened--;
		}
		if (opened < 0) return false;
	}
	return opened == 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int t;
    cin >> t;

    while(t--) {
    	string s;
    	cin >> s;

    	bool can = false;
    	vector<char> naw{'(', ')'};
    	for (char a : naw)
    		for (char b : naw)
    			for (char c : naw)
    				can |= is_valid(s, a, b, c);
    	if (can)
    		cout << "YES\n";
    	else
    		cout << "NO\n";
    }

    return 0;
}