### constant

#         0    1     2    3     4    5    6     7    8     9    10   11
TONES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
EXTS = ['', '7', 'M7', 'm', 'm7']

CMPNTS = [
  [0, 4, 7],	 # C   = C,E,G
  [0, 4, 7, 10], # C7  = C,E,G,A#
  [0, 4, 7, 11], # CM7 = C,E,G,B
  [0, 3, 7],	 # Cm  = C,D#,G
  [0, 3, 7, 10]	 # Cm7 = C,D#,G,A#
]

#           0    1     2      3     4      5      6     7     8
TNSNS0 = ['-9', '9', '+9', '-11', '11', '+11', '-13', '13', '+13']
#          C#    D    D#      E     F     F#     G#     A     A#
TADDS  = [  1,   2,    3,     4,    5,     6,     8,    9,    10]

TNSNS1 = ['-5', '+5']
#          F#    G#
TMODS  = [ -1,    1]

NT = TONES.length
NE = EXTS.length
NTNS0 = TNSNS0.length
NTNS1 = TNSNS1.length

### global variables

### subroutines

def cmpntstr(cmpnt)
  cmpnt.map{|t| TONES[t]}.sort.join
end

### main

chash = Hash.new

for root in (0...NT)
  for ext in (0...NE)
    base = TONES[root] + EXTS[ext]
    cmpnt = CMPNTS[ext].map{|t| (root + t) % NT}
    cstr = cmpntstr(cmpnt)

    chash[cstr] = [] if chash[cstr].nil?
    chash[cstr] << base
    #p [base, cstr]
    
    for tns0 in (0...NTNS0)
      cname0 = base + '(' + TNSNS0[tns0] + ')'
      cmpnt0 = cmpnt + [(root + TADDS[tns0]) % NT]
      cstr0 = cmpntstr(cmpnt0)

      chash[cstr0] = [] if chash[cstr0].nil?
      chash[cstr0] << cname0
      #p [cname0, cstr0]
    end

    for tns1 in (0...NTNS1)
      cname1 = base + '(' + TNSNS1[tns1] + ')'
      cmpnt1 = cmpnt.clone
      cmpnt1[2] = (cmpnt1[2] + TMODS[tns1]) % NT
      cstr1 = cmpntstr(cmpnt1)
      
      chash[cstr1] = [] if chash[cstr1].nil?
      chash[cstr1] << cname1
      #p [cname1, cstr1]
    end
  end
end
#p chash; exit 0
#p chash['CEG']; exit 0

n = gets.to_i

n.times do
  cols = gets.strip.split
  cols.shift

  cnames = chash[cols.sort.join]
  if cnames.nil?
    puts 'UNKNOWN'
  else
    puts cnames.join(' ')
  end
end