var obj={
C:0,
Cs:1,
D:2,
Ds:3,
E:4,
F:5,
Fs:6,
G:7,
Gs:8,
A:9,
As:10,
B:11
};
var cde=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];
var chord=[
[0,4,7],
[0,4,7,10],
[0,4,7,11],
[0,3,7],
[0,3,7,10],
[0,4,6],
[0,4,6,10],
[0,4,6,11],
[0,3,6],
[0,3,6,10],
[0,4,8],
[0,4,8,10],
[0,4,8,11],
[0,3,8],
[0,3,8,10]
];
var name=[
"","7","M7","m","m7",
"(-5)","7(-5)","M7(-5)","m(-5)","m7(-5)",
"(+5)","7(+5)","M7(+5)","m(+5)","m7(+5)"];
var tension={
1:"(-9)",
2:"(9)",
3:"(+9)",
4:"(-11)",
5:"(11)",
6:"(+11)",
8:"(-13)",
9:"(13)",
10:"(+13)"
};
var CHORD={};
chord.forEach(function(v,i){
   CHORD[v.join(",")]=name[i];
   if(/5\)/.test(name[i])!=true){
      for(var k in tension){
         if(v.indexOf(k-0)==-1){
            CHORD[v.concat(k-0).sort(function(a,b){return a-b}).join(",")]=name[i]+tension[k];
        }
      }
   }
});
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
input=input.replace(/\#/g,"s");
var arr=input.trim().split("\n");
var n=arr.shift()-0;
while(n--){
   var ans=[];
   var ary=arr.shift().split(" ");
   ary.shift();
   var NumAry=ary.map(function(v){return obj[v];});
   NumAry.sort(function(a,b){return a-b;});
   NumAry.forEach(function(v,i,array){
      var x=cde[v];
      var minus=0;
      while(v!=0){
         v--;
         minus--;
      }
      var A=array.map(function(value,index){
         return (value+minus<0)?value+minus+12:value+minus;
      });
      A.sort(function(a,b){return a-b;});
      if(CHORD.hasOwnProperty(A.join(","))){
         var NAME=CHORD[A.join(",")];
         if(NAME=="m(-11)"){
            ans.push(x+"(+9)");
            ans.push(x+NAME);
         }else if(NAME=="7"){
            ans.push(x+NAME);
            ans.push(x+"(+13)");
         }else if(NAME=="m7(-11)"){
            ans.push(x+"7(+9)");
            ans.push(x+NAME);
         }else if(NAME=="m7"){
            ans.push(x+NAME);
            ans.push(x+"m(+13)");
         }else{
            ans.push(x+NAME);      
         }
      }
   });
   ans=(ans.length==0)?"UNKNOWN":ans.join(" ");
   console.log(ans);
}