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

char a[60],cp1[60], cp2[60], q[60];

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        scanf("%s", a);
        int str = strlen(a);
        for (int i = 0; i < str; ++i) {
            cp1[i] = cp2[i] = 0;
        }
        if (a[0] == a[str-1])   printf("NO\n");
        else {
            for (int i = 0; i < str; ++i) {
                if (a[i] == a[0]) {
                    cp1[i] = cp2[i] = '(';
                }
                else if (a[i] == a[str-1]) {
                    cp1[i] = cp2[i] = ')';
                }
                else {
                    cp1[i] = '(';
                    cp2[i] = ')';
                }
            }
            bool flag = true;
            int ans = 0;
            for (int i = 0; i < str; ++i) {
                if (cp1[i] == '(') {
                    ++ans;
                }
                else {
                    if (ans == 0) {
                        flag = false;
                        break;
                    }
                    --ans;
                }
            }
            if (ans == 0 && flag == true) {
                printf("YES\n");
                continue;
            }
            else {
                ans = 0;
                for (int i = 0; i < str; ++i) {
                    if (cp2[i] == '(') {
                        ++ans;
                    }
                    else {
                        if (ans == 0) {
                            flag = false;
                            break;
                        }
                        --ans;
                    }
                }
            }
            if (ans == 0 && flag == true)   printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
}