Problem: In this problem, you are required to write a program that enumerates all chord names for given tones.

We suppose an ordinary scale that consists of the following 12 tones:

C, C# , D, D# , E, F, F# , G, G# , A, A# , B

Two adjacent tones are different by a half step; the right one is higher. Hence, for example, the tone G is higher than the tone E by three half steps. In addition, the tone C is higher than the tone B by a half step. Strictly speaking, the tone C of the next octave follows the tone B, but octaves do not matter in this problem.

A chord consists of two or more different tones, and is called by its chord name. A chord may be represented by multiple chord names, but each chord name represents exactly one set of tones.

In general, a chord is represented by a basic chord pattern (base chord) and additional tones (tension) as needed. In this problem, we consider five basic patterns as listed below, and up to one additional tone.

<image>

Figure 1: Base chords (only shown those built on C)

The chords listed above are built on the tone C, and thus their names begin with C. The tone that a chord is built on (the tone C for these chords) is called the root of the chord.

A chord specifies its root by an absolute tone, and its other components by tones relative to its root. Thus we can obtain another chord by shifting all components of a chord. For example, the chord name D represents a chord consisting of the tones D, F# and A, which are the shifted-up tones of C, E and G (which are components of the chord C) by two half steps.

An additional tone, a tension, is represented by a number that may be preceding a plus or minus sign, and designated parentheses after the basic pattern. The figure below denotes which number is used to indicate each tone.

<image>

Figure 2: Tensions for C chords

For example, C(9) represents the chord C with the additional tone D, that is, a chord that consists of C, D, E and G. Similarly, C(+11) represents the chord C plus the tone F#.

The numbers that specify tensions denote relative tones to the roots of chords like the compo- nents of the chords. Thus change of the root also changes the tones specified by the number, as illustrated below.

<image>

Figure 3: Tensions for E chords

+5 and -5 are the special tensions. They do not indicate to add another tone to the chords, but to sharp (shift half-step up) or flat (shift half-step down) the fifth tone (the tone seven half steps higher than the root). Therefore, for example, C(+5) represents a chord that consists of C, E and G# , not C, E, G and G#.

Figure 4 describes the syntax of chords in Backus-Naur Form.

Now suppose we find chord names for the tones C, E and G. First, we easily find the chord C consists of the tones C, E and G by looking up the base chord table shown above. Therefore ‘C’ should be printed. We have one more chord name for those tones. The chord Em obviously represents the set of tones E, G and B. Here, if you sharp the tone B, we have the set of tones E, G and C. Such modification can be specified by a tension, +5 in this case. Thus ‘Em(+5)’ should also be printed.

<image>

Figure 4: Syntax of chords in BNF



Input

The first line of input contains an integer N, which indicates the number of test cases.

Each line after that contains one test case. A test case consists of an integer m (3 ≤ m ≤ 5) followed by m tones. There is exactly one space character between each tones. The same tone does not appear more than once in one test case.

Tones are given as described above.

Output

Your program should output one line for each test case.

It should enumerate all chord names that completely match the set of tones given as input (i.e. the set of tones represented by each chord name must be equal to that of input) in any order.

No chord name should be output more than once. Chord names must be separated by exactly one space character. No extra space is allowed.

If no chord name matches the set of tones, your program should just print ‘UNKNOWN’ (note that this word must be written in capital letters).

Example

Input

5
3 C E G
3 C E G#
4 C A G E
5 F A C E D
3 C D E


Output

C Em(+5)
C(+5) E(+5) G#(+5)
C(13) Am7 Am(+13)
Dm7(9) FM7(13)
UNKNOWN

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}


int main(){
  map<string,int> toneToIdx;
  string idxToTone[]={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
  // コードの名前とそのcomponent
  for(int i=0;i<12;i++)toneToIdx[idxToTone[i]]=i;
  map<string,set<int> > chords;
  {
    set<int> st;
    st.insert(toneToIdx["C"]);
    st.insert(toneToIdx["E"]);
    st.insert(toneToIdx["G"]);
    chords["C"]=st;
  }
  {
    set<int> st;
    st.insert(toneToIdx["C"]);
    st.insert(toneToIdx["E"]);
    st.insert(toneToIdx["G"]);
    st.insert(toneToIdx["A#"]);
    chords["C7"]=st;
  }
  {
    set<int> st;
    st.insert(toneToIdx["C"]);
    st.insert(toneToIdx["E"]);
    st.insert(toneToIdx["G"]);
    st.insert(toneToIdx["B"]);
    chords["CM7"]=st;
  }
  {
    set<int> st;
    st.insert(toneToIdx["C"]);
    st.insert(toneToIdx["D#"]);
    st.insert(toneToIdx["G"]);
    chords["Cm"]=st;
  }
  {
    set<int> st;
    st.insert(toneToIdx["C"]);
    st.insert(toneToIdx["D#"]);
    st.insert(toneToIdx["G"]);
    st.insert(toneToIdx["A#"]);
    chords["Cm7"]=st;
  }

  typedef pair<string,string> pss;
  pss pars[]={pss("-9","C#"),pss("9","D"),pss("+9","D#")
              ,pss("-11","E"),pss("11","F"),pss("+11","F#")
              ,pss("-13","G#"),pss("13","A"),pss("+13","A#")
              ,pss("-5",""),pss("+5",""),pss("","")};              
  int N;
  cin>>N;
  while(N--){
    int M;
    set<int> inSets;
    vector<string> ress;
    cin>>M;
    for(int i=0;i<M;i++){
      string s;
      cin>>s;
      inSets.insert(toneToIdx[s]);
      //cout<<toneToIdx[s]<<" ";
    }
    //cout<<endl;
    // すべてのtoneをrootに
    for(int i=0;i<12;i++){
      // 5種類のコードを使用
      for(map<string,set<int> >::iterator it=chords.begin();it!=chords.end();it++){
        // 括弧の中身をどうするか
        for(int j=0;j<12;j++){
          string r=idxToTone[i]+it->first.substr(1);
          if(pars[j].first!="")r+="("+pars[j].first+")";
          //cout<<r<<endl;
          set<int> nowSt;
          for(set<int>::iterator iit=it->second.begin();iit!=it->second.end();iit++)
            nowSt.insert((*iit+i)%12);
          if(pars[j].first==""){}
          else if(pars[j].first[1]=='5'){
            // replace
            int tgt=(i+7)%12;
            // assert(it->second.size()==nowSt.size());
            // for(set<int>::iterator iit=nowSt.begin();iit!=nowSt.end();iit++){
            //   cout<<*iit<<" ";
            // }
            // cout<<endl;
            nowSt.erase(tgt);
            if(pars[j].first[0]=='+')nowSt.insert((tgt+1)%12);
            else nowSt.insert((tgt+11)%12);
          }
          // 普通に処理
          else{
            if(nowSt.count((i+toneToIdx[pars[j].second])%12))continue;
            nowSt.insert((i+toneToIdx[pars[j].second])%12);
          }
          if(inSets==nowSt){
            ress.push_back(r);
          }
        }
      }
    }
    if((int)ress.size()==0)cout<<"UNKNOWN"<<endl;
    else{
      for(int i=0;i<(int)ress.size();i++){
        cout<<ress[i];
        if(i==(int)ress.size()-1)cout<<endl;
        else cout<<" ";
      }
    }
  }
  
  return 0;
}