// AOJ 2027: Reading a Chord
// 2017.12.11 bal4u@uu

#include <stdio.h>
#include <string.h>

char tones[12][3] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
char base[5][3] = {"","7","M7","m","m7"};
char tension[12][4] = {"","-9","9","+9","-11","11","+11","","-13","13","+13"};
char tr['G'+1]['#'+1];
char f[12], t[12];
char ans[100][10]; int sz;
char tbl[5][4] = {{4,7},{4,7,10},{4,7,11},{3,7},{3,7,10}};

int main()
{
	int cno, m, i, a, b, u, v;
	char buf[5];

	tr['C'][0] = 0, tr['C']['#'] = 1, tr['D'][0] = 2, tr['D']['#'] = 3;
	tr['E'][0] = 4, tr['F'][0] = 5, tr['F']['#'] = 6;
	tr['G'][0] = 7, tr['G']['#'] = 8, tr['A'][0] = 9, tr['A']['#'] = 10;
    tr['B'][0] = 11;

	scanf("%d", &cno);
	while (cno--) {
		scanf("%d", &m);
		memset(f, 0, sizeof(f));
		while (m--) {
			scanf("%s", buf);
			if (buf[1] != '#') buf[1] = 0;
			f[tr[buf[0]][buf[1]]] = 1;
		}

		sz = 0;
		for (a = 0; a < 12; a++) for (b = 0; b < 5; b++) {
			memset(t, 0, sizeof(t));
			t[a] = 1;
			for (i = 0; tbl[b][i]; i++) t[(a+tbl[b][i])%12] = 1;

			if (!memcmp(f, t, sizeof(f))) {
				sprintf(ans[sz++], "%s%s", tones[a], base[b]);
				continue;
			}

			for (i = 1; i <= 10; i++) {
				if (i == 7) continue;
				u = (a+i)%12;
				v = t[u], t[u] = 1;
				if (!memcmp(f, t, sizeof(f)))
					sprintf(ans[sz++], "%s%s(%s)", tones[a], base[b], tension[i]);
				t[u] = v;
			}

			t[(a+7)%12] = 0, t[(a+18)%12] = 1;
			if (!memcmp(f, t, sizeof(f)))
				sprintf(ans[sz++], "%s%s(-5)", tones[a], base[b]);

			t[(a+18)%12] = 0; t[(a+8)%12] = 1;
			if (!memcmp(f, t, sizeof(f)))
				sprintf(ans[sz++], "%s%s(+5)", tones[a], base[b]);
		}

		if (!sz) puts("UNKNOWN");
		else {
			printf(ans[0]);
			for (i = 1; i < sz; i++) putchar(' '), printf(ans[i]);
			putchar('\n');
		}
	}
	return 0;
}