#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define MP make_pair
#define pb push_back

int C[]={0,4,7};
int C7[]={0,4,7,10};
int CM7[]={0,4,7,11};
int Cm[]={0,3,7};
int Cm7[]={0,3,7,10};

map<int, string> d;
map<string, int> dic;
map<int, string> rev;

vector<string> ans;

void init()
{
	d[1]="-9";
	d[2]="9";
	d[3]="+9";
	d[4]="-11";
	d[5]="11";
	d[6]="+11";
	d[8]="-13";
	d[9]="13";
	d[10]="+13";
	
	dic["C"]	= 0;
	dic["C#"]	= 1;
	dic["D"]	= 2;
	dic["D#"]	= 3;
	dic["E"]	= 4;
	dic["F"]	= 5;
	dic["F#"]	= 6;
	dic["G"]	= 7;
	dic["G#"]	= 8;
	dic["A"]	= 9;
	dic["A#"]	= 10;
	dic["B"]	= 11;
	
	rev[0]	= "C";
	rev[1]	= "C#";
	rev[2]	= "D";
	rev[3]	= "D#";
	rev[4]	= "E";
	rev[5]	= "F";
	rev[6]	= "F#";
	rev[7]	= "G";
	rev[8]	= "G#";
	rev[9]	= "A";
	rev[10]	= "A#";
	rev[11]	= "B";
}

void ps(string s, int orig, string type)
{
	string pat;

	pat += rev[orig] + type;
	if(!s.empty()) pat += "("+ s + ")";

	ans.pb(pat);
}

bool check(vector<int> c, vector<int> p)
{
	if(c.size()!= p.size()) return false;

	sort(c.begin(), c.end());
	sort(p.begin(), p.end());
	
	for(int i=0; i<c.size(); i++)
		if(c[i]!=p[i]) return false;

	return true;
}

void ctension(vector<int> c, vector<int> p, int orig, string type)
{
	for(int i=1; i<=10; i++)
	{
		if(i==7) continue;
		vector<int> t(c);
		t.pb((orig+i)%12);
		if(check(t,p)) ps(d[i], orig, type);
	}

	vector<int>::iterator it=find(c.begin(), c.end(), (orig+7)%12);
	
	*it = ((*it)+11)%12;

	if(check(c,p)) ps("-5", orig, type);

	*it = ((*it)+2)%12;
	if(check(c,p)) ps("+5", orig, type);
}

void createC(vector<int> p)
{
	vector<int> c;
	for(int i=0; i<3; i++)
		c.pb(C[i]);

	for(int i=0; i<12; i++)
	{
		if(check(c,p)) ps("",i,"");
		ctension(c,p,i,"");
		
		for(int j=0; j<3; j++)
			c[j]=(c[j]+1)%12;
	}
}

void createC7(vector<int> p)
{

	vector<int> c;
	for(int i=0; i<4; i++)
		c.pb(C7[i]);

	for(int i=0; i<12; i++)
	{
		if(check(c,p)) ps("",i,"7");
		ctension(c,p,i,"7");
		
		for(int j=0; j<4; j++)
			c[j]=(c[j]+1)%12;
	}
}

void createCM7(vector<int> p)
{
	vector<int> c;
	for(int i=0; i<4; i++)
		c.pb(CM7[i]);

	for(int i=0; i<12; i++)
	{
		if(check(c,p)) ps("",i,"M7");
		ctension(c,p,i,"M7");
		
		for(int j=0; j<4; j++)
			c[j]=(c[j]+1)%12;
	}
}
void createCm(vector<int> p)
{
	vector<int> c;
	for(int j=0; j<3; j++)
		c.pb(Cm[j]);

	for(int i=0; i<12; i++)
	{
		if(check(c,p)) ps("",i,"m");
		ctension(c,p,i,"m");
		
		for(int j=0; j<3; j++)
			c[j]=(c[j]+1)%12;

	}
	
}

void createCm7(vector<int> p)
{
	vector<int> c;
	for(int j=0; j<4; j++)
		c.pb(Cm7[j]);

	for(int i=0; i<12; i++)
	{
		if(check(c,p)) ps("",i,"m7");
		ctension(c,p,i,"m7");
		
		for(int j=0; j<4; j++)
			c[j]=(c[j]+1)%12;

	}
}

void create(vector<int> p)
{
	createC(p);
	createC7(p);
	createCM7(p);
	createCm(p);
	createCm7(p);
}

int main()
{
	int N,M;
	cin >> N;
	
	init();
	
	while(N--)
	{
		ans.clear();

		vector<int> n;
		cin >> M;
		while(M--)
		{
			string s;
			cin >> s;
			n.push_back(dic[s]);
		}
		
		create(n);

		if(ans.size()!=0)
		{
			for(int i=0; i<ans.size(); i++)
			{
				if(i!=0) cout << " ";
				cout << ans[i];
			}
			cout << endl;
		}
		else
		{
			cout << "UNKNOWN" << endl;
		}
	}
}

Measured memory_bytes: 936