#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define F first
#define S second
#define ll long long
#define ld double long
#define ull unsigned long long
//#define endl '\n'


const ll N = 3e5 + 36;
const ll M = 1e3 + 36;
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;
const ll MOD1 = 888888901;
const ll MOD2 = 999988901;
const ll X[8] = {1, -1, 2, 2, -2, -2, 1, -1};
const ll Y[8] = {2, 2, 1, -1, 1, -1, -2, -2};
const ld PI = 3.14159265358979323846;
const ld EPS = 1e-10;

//tree < pair < string, int >, null_type, less < pair < string, int > >, rb_tree_tag, tree_order_statistics_node_update > a;

//mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
mt19937 gen(991281);

ll a[N];


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int t;
    cin >> t;
    while (t--){
        string s;
        cin >> s;
        bool f = 0;
        for (int i(0); i < 8; ++i){
            string now = "";
            for (int j(0); j < int(s.size()); ++j){
                if (i & (1 << int(s[j] - 'A'))){
                    now += '(';
                } else {
                    now += ')';
                }
            }
            int sum = 0;
            for (int j(0); j < int(s.size()); ++j){
                if (now[j] == '('){
                    ++sum;
                } else {
                    --sum;
                }
                if (sum < 0){
                    break;
                }
            }
            if (sum == 0){
                f = 1;
                break;
            }
        }
        if (f){
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
