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


#pragma GCC                     optimize ("Ofast")
#pragma GCC                     optimize("O3")
#define db                      double
#define ll                      long long
#define ull                     unsigned long long
#define lo(i,a,n,x)             for(i=a;i<=n;i=i+x)
#define loi(i,a,n,x)            for(i=a;i>=n;i=i-x)
#define sc                      scanf
#define pr                      printf
#define ms(a,b)                 memset(a, b, sizeof(a))
#define pb(a)                   push_back(a)
#define pop()                   pop_back()
#define mp                      make_pair
#define VI                      vector <int>
#define PII                     pair <int,int>
#define PLL                     pair <long long,long long>
#define ff                      first
#define ss                      second
#define sqr(x)                  (x)*(x)
#define SZ(a)                   (int)a.size()
#define FAST_CIN                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stlloop(v)              for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define UNIQUE(v)               (v).erase(unique((v).begin(),(v).end()),(v).end())
#define POPCOUNT(m)             __builtin_popcountll(m)
#define RIGHTMOST(m)            __builtin_ctzll(m)
#define LEFTMOST(x)             (63-__builtin_clzll((x)))
#define ODD(x)                  (((x)&1)==0?(0):(1))
#define TEST_CASE(t)            for(int love=1;love<=t;love++)
#define PRINT_CASE              printf("Case %d: ",love)
#define LINE_PRINT_CASE         printf("Case %d:\n",z)
#define all(a)                  a.begin(),a.end()
#define SORT(x)                 sort(x.begin(), x.end())
#define REV(x)                  reverse(x.begin(), x.end())
#define DBG0                    cerr << __LINE__ << ": ----" << '\n'
#define DBG(...)                cerr << __LINE__ <<':' << "(" << #__VA_ARGS__ << ")"<< " = ", dbg_out(__VA_ARGS__)
#define GCD(a, b)               __gcd(a, b)
#define lcm(a, b)               (a)*((b)/gcd(a,b))
#define end0                    "\n"
#define end1                    cout<<"\n";
#define Pi                      acos(-1)
#define mod                     1000000007
#define intlim                  2147483648
#define infinity                (1<<28)
#define EPS                     10E-9

//----------------------------------------------------------------
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << ' ' << H;
     dbg_out(T...);
}
//----------------------------------------------------------------

bool compare(const tuple<int, int, int>& a,
               const tuple<int, int, int>& b)
{
    return (get<2>(a) < get<2>(b));
}

void solve()
{int i,a,b,c,j,k,l,w,h,n,m,ma,r,z,e,t,tt,x5,y5;



    char x[55];
    int y[8];

    memset(y,0,sizeof(y));
    cin>>x;

    for(i=0;i<strlen(x);i++)
    {
        if(x[i]=='A')
        {
            y[0]++;
            y[1]++;
            y[2]++;
            y[3]++;
            y[4]--;
            y[5]--;
            y[6]--;
            y[7]--;
        }
        if(x[i]=='B')
        {
            y[0]--;
            y[1]++;
            y[2]++;
            y[3]--;
            y[4]--;
            y[5]++;
            y[6]++;
            y[7]--;
        }
        if(x[i]=='C')
        {
            y[0]--;
            y[1]++;
            y[2]--;
            y[3]++;
            y[4]--;
            y[5]++;
            y[6]--;
            y[7]++;
        }
        for(j=0;j<8;j++)
        {
            if(y[j]<0){y[j]=-100;}
        }
    }

    for(i=0;i<8;i++)
    {
        if(y[i]==0)
        {
            cout<<"YES"<<endl;
            return;
        }
    }
    cout<<"NO"<<endl;
    return;



}
long long i,j,k,l,n,m,ma,y,r,c[567890],z,s,e,t,tt,x5,y5;


int main(){
    cin>>t;
    while(t--){solve();}
}



### Prompt

Generate a cpp solution to the following problem:

You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.

A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.

You want to find a string b that consists of n characters such that: 

  * b is a regular bracket sequence; 
  * if for some i and j (1 ≤ i, j ≤ n) a_i=a_j, then b_i=b_j. 



In other words, you want to replace all occurrences of 'A' with the same type of bracket, then all occurrences of 'B' with the same type of bracket and all occurrences of 'C' with the same type of bracket.

Your task is to determine if such a string b exists.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.

Then the descriptions of t testcases follow.

The only line of each testcase contains a string a. a consists only of uppercase letters 'A', 'B' and 'C'. Let n be the length of a. It is guaranteed that n is even and 2 ≤ n ≤ 50.

Output

For each testcase print "YES" if there exists such a string b that: 

  * b is a regular bracket sequence; 
  * if for some i and j (1 ≤ i, j ≤ n) a_i=a_j, then b_i=b_j. 



Otherwise, print "NO".

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

Example

Input


4
AABBAC
CACA
BBBBAC
ABCA


Output


YES
YES
NO
NO

Note

In the first testcase one of the possible strings b is "(())()".

In the second testcase one of the possible strings b is "()()".

### Response

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


#pragma GCC                     optimize ("Ofast")
#pragma GCC                     optimize("O3")
#define db                      double
#define ll                      long long
#define ull                     unsigned long long
#define lo(i,a,n,x)             for(i=a;i<=n;i=i+x)
#define loi(i,a,n,x)            for(i=a;i>=n;i=i-x)
#define sc                      scanf
#define pr                      printf
#define ms(a,b)                 memset(a, b, sizeof(a))
#define pb(a)                   push_back(a)
#define pop()                   pop_back()
#define mp                      make_pair
#define VI                      vector <int>
#define PII                     pair <int,int>
#define PLL                     pair <long long,long long>
#define ff                      first
#define ss                      second
#define sqr(x)                  (x)*(x)
#define SZ(a)                   (int)a.size()
#define FAST_CIN                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stlloop(v)              for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define UNIQUE(v)               (v).erase(unique((v).begin(),(v).end()),(v).end())
#define POPCOUNT(m)             __builtin_popcountll(m)
#define RIGHTMOST(m)            __builtin_ctzll(m)
#define LEFTMOST(x)             (63-__builtin_clzll((x)))
#define ODD(x)                  (((x)&1)==0?(0):(1))
#define TEST_CASE(t)            for(int love=1;love<=t;love++)
#define PRINT_CASE              printf("Case %d: ",love)
#define LINE_PRINT_CASE         printf("Case %d:\n",z)
#define all(a)                  a.begin(),a.end()
#define SORT(x)                 sort(x.begin(), x.end())
#define REV(x)                  reverse(x.begin(), x.end())
#define DBG0                    cerr << __LINE__ << ": ----" << '\n'
#define DBG(...)                cerr << __LINE__ <<':' << "(" << #__VA_ARGS__ << ")"<< " = ", dbg_out(__VA_ARGS__)
#define GCD(a, b)               __gcd(a, b)
#define lcm(a, b)               (a)*((b)/gcd(a,b))
#define end0                    "\n"
#define end1                    cout<<"\n";
#define Pi                      acos(-1)
#define mod                     1000000007
#define intlim                  2147483648
#define infinity                (1<<28)
#define EPS                     10E-9

//----------------------------------------------------------------
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << ' ' << H;
     dbg_out(T...);
}
//----------------------------------------------------------------

bool compare(const tuple<int, int, int>& a,
               const tuple<int, int, int>& b)
{
    return (get<2>(a) < get<2>(b));
}

void solve()
{int i,a,b,c,j,k,l,w,h,n,m,ma,r,z,e,t,tt,x5,y5;



    char x[55];
    int y[8];

    memset(y,0,sizeof(y));
    cin>>x;

    for(i=0;i<strlen(x);i++)
    {
        if(x[i]=='A')
        {
            y[0]++;
            y[1]++;
            y[2]++;
            y[3]++;
            y[4]--;
            y[5]--;
            y[6]--;
            y[7]--;
        }
        if(x[i]=='B')
        {
            y[0]--;
            y[1]++;
            y[2]++;
            y[3]--;
            y[4]--;
            y[5]++;
            y[6]++;
            y[7]--;
        }
        if(x[i]=='C')
        {
            y[0]--;
            y[1]++;
            y[2]--;
            y[3]++;
            y[4]--;
            y[5]++;
            y[6]--;
            y[7]++;
        }
        for(j=0;j<8;j++)
        {
            if(y[j]<0){y[j]=-100;}
        }
    }

    for(i=0;i<8;i++)
    {
        if(y[i]==0)
        {
            cout<<"YES"<<endl;
            return;
        }
    }
    cout<<"NO"<<endl;
    return;



}
long long i,j,k,l,n,m,ma,y,r,c[567890],z,s,e,t,tt,x5,y5;


int main(){
    cin>>t;
    while(t--){solve();}
}



```