#include <bits/stdc++.h>
using namespace std;

bool ok(char a, char b, int i, string s){
    int flag = 0;
    for(auto lol : s){
        if(lol == a || lol == b) flag += i;
        else flag -= i;
        if(flag < 0) return false;
    }
    if(flag == 0) return true;
    return false;
}

int main(){
    int t;
    string s;
    cin >> t;
    while(t--){
        cin >> s;
        if(ok('A','B',1,s)) cout << "YES\n";
        else if(ok('A','B',-1,s)) cout << "YES\n";
        else if(ok('B','C',1,s)) cout << "YES\n";
        else if(ok('B','C',-1,s)) cout << "YES\n";
        else if(ok('C','A',1,s)) cout << "YES\n";
        else if(ok('C','A',-1,s)) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}
