#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 12

struct Info{
	Info(int arg_tone_id,int arg_code_id,int arg_tension_op,int arg_tension_value,bool arg_is_tension){
		tone_id = arg_tone_id;
		code_id = arg_code_id;
		tension_op = arg_tension_op;
		tension_value = arg_tension_value;
		is_tension = arg_is_tension;
	}
	int tone_id,code_id,tension_op,tension_value;
	bool is_tension;
};

int POW[NUM];
int tension_array[4] = {9,11,13,5};
int diff_table[3][3] = {{1,2,3},{4,5,6},{8,9,10}};
char tone_name[NUM][3] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
char code_name[NUM][3] = {"@","7","M7","m","m7"};
vector<int> component[5];
vector<Info> ANS;

bool strCmp(char* base, char* comp){
	int length1,length2;
	for(length1=0;base[length1] != '\0';length1++);
	for(length2=0;comp[length2] != '\0';length2++);
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

//該当するtoneのidを返却する
int get_id(char buf[3]){

	for(int i = 0; i < NUM; i++){
		if(strCmp(tone_name[i],buf)){
			return i;
		}
	}

	return -1;
}

int get_state(bool check[NUM]){

	int ret = 0;

	for(int i = 0; i < NUM; i++){
		if(check[i]){
			ret += POW[i];
		}
	}

	return ret;
}

void print_Info(Info info){

	printf("%s",tone_name[info.tone_id]);

	if(info.code_id != 0){

		printf("%s",code_name[info.code_id]);
	}
	if(!info.is_tension)return;

	printf("(");

	if(info.tension_op != 0){

		if(info.tension_op > 0){

			printf("+");

		}else{

			printf("-");
		}
	}
	printf("%d",info.tension_value);
	printf(")");
}

void dfs(int ans_state){

	int tmp,tmp_state,tmp_value,diff,tmp_loc;
	bool check[12],pre;

	for(int base_tone = 0; base_tone < NUM; base_tone++){
		for(int cord = 0; cord < 5; cord++){

			for(int i = 0; i < NUM; i++){
				check[i] = false;
			}
			for(int i = 0; i < component[cord].size(); i++){
				check[(base_tone+component[cord][i])%12] = true;
			}

			tmp_state = get_state(check);

			if(tmp_state == ans_state){
				ANS.push_back(Info(base_tone,cord,0,0,false)); //テンション無しで見つかればcontinue
				continue;
			}

			//テンションを全探索
			for(int t = 0; t < 4; t++){

				tmp_value = tension_array[t];

				if(tmp_value != 5){
					//各数字について、マイナス、ノーマル、プラスの3つ
					for(int a = 0; a < 3; a++){

						diff = diff_table[t][a]; //base_toneからの相対位置
						tmp_loc = (base_tone+diff)%12;
						pre = check[tmp_loc];
						check[tmp_loc] = true;
						tmp_state = get_state(check);
						if(tmp_state == ans_state){
							ANS.push_back(Info(base_tone,cord,a-1,tmp_value,true));
						}
						check[tmp_loc] = pre;
					}

				}else{ //tmp_value == 5

					//★base_toneより7半音高い音を上下させる
					tmp_loc = (base_tone+7)%12;
					check[tmp_loc] = false;

					//マイナス
					pre = check[(tmp_loc+11)%12];
					check[(tmp_loc+11)%12] = true; //-1の代わりに11
					tmp_state = get_state(check);
					if(tmp_state == ans_state){
						ANS.push_back(Info(base_tone,cord,-1,tmp_value,true));
					}
					check[(tmp_loc+11)%12] = pre;

					//プラス
					pre = check[(tmp_loc+1)%12];
					check[(tmp_loc+1)%12] = true;
					tmp_state = get_state(check);
					if(tmp_state == ans_state){
						ANS.push_back(Info(base_tone,cord,1,tmp_value,true));
					}
					check[(tmp_loc+1)%12] = pre;

					check[tmp_loc] = true;
				}
			}
		}
	}
}


void func(){

	int num;
	char buf[3];

	scanf("%d",&num);

	int tmp_state = 0;

	for(int loop = 0; loop < num; loop++){
		scanf("%s",buf);
		tmp_state += POW[get_id(buf)];
	}

	ANS.clear();

	dfs(tmp_state);

	if(ANS.size() == 0){
		printf("UNKNOWN\n");
		return;
	}

	print_Info(ANS[0]);
	for(int i = 1; i < ANS.size(); i++){
		printf(" ");
		print_Info(ANS[i]);
	}

	printf("\n");
}


int main(){

	//何もなし
	component[0].push_back(0);
	component[0].push_back(4);
	component[0].push_back(7);

	//7
	component[1].push_back(0);
	component[1].push_back(4);
	component[1].push_back(7);
	component[1].push_back(10);

	//M7
	component[2].push_back(0);
	component[2].push_back(4);
	component[2].push_back(7);
	component[2].push_back(11);

	//m
	component[3].push_back(0);
	component[3].push_back(3);
	component[3].push_back(7);

	//m7
	component[4].push_back(0);
	component[4].push_back(3);
	component[4].push_back(7);
	component[4].push_back(10);


	POW[0] = 1;
	for(int i = 1; i < NUM; i++){
		POW[i] = POW[i-1]*2;
	}
	int num_case;

	scanf("%d",&num_case);

	for(int loop = 0; loop < num_case; loop++){
		func();
	}

	return 0;
}



Measured memory_bytes: 3164