#include <bits/stdc++.h>

using namespace std;

bool check(const string& s) {
  int depth = 0, current = 0;
  for (int i = 0; i < int(s.size()); ++i) {
    if (s[i] == '(') current++;
    else current--;
    depth = min(depth, current);
  }
  return (current == 0 && depth >= 0);
}

bool solve() {
  string s;
  cin >> s;
  for (int w = 0; w < (1 << 3); ++w) {
    string tmp = s;
    for (int j = 0; j < int(tmp.size()); ++j) {
      if ((w >> (tmp[j] - 'A')) & 1)
        tmp[j] = '(';
      else
        tmp[j] = ')';
    }
    if (check(tmp))
      return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  for (cin >> t; t--;) {
    cout << (solve() ? "YES" : "NO") << '\n';
  }
  return 0;
}