#include<bits/stdc++.h>
using namespace std;
long* SieveOfEratosthenes(int n)
{
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
bool prime[n+1];
memset(prime, true, sizeof(prime));
long *arr=new long[78499];
for (int p=2; p*p<=n; p++)
{
// If prime[p] is not changed, then it is a prime
if (prime[p] == true)
{
// Update all multiples of p greater than or
// equal to the square of it
// numbers which are multiple of p and are
// less than p^2 are already been marked.
for (int i=p*p; i<=n; i += p)
prime[i] = false;
}
}
int flag=0;
// Print all prime numbers
for (int p=2; p<=n; p++)
if (prime[p]){
// cout << p << " ";
arr[flag++]=p;
}
// cout<<flag<<endl;
return arr;
}
int main(){
int t=0;
cin>>t;
int cse=0;
long *arr=SieveOfEratosthenes(100000);
while(t--){
cse+=1;
set<long> str;
int n=0;
int m=0;
cin>>m>>n;
long num[n];
long low[1][2];
low[0][0]=1000000;
int flag=0;
for (int i = 0; i < n; ++i)
{
long temp=0;
cin>>temp;
num[i]=temp;
if(temp<low[0][0]){
low[0][0]=temp;
low[0][1]=i;
flag=i;
}
}
long pair[1][2];
for (int i = 0; i < 78499; ++i)
{
if(fmod(low[0][0],arr[i])==0){
pair[0][0]=arr[i];
pair[0][1]=low[0][0]/arr[i];
break;
}
}
//pair contains the decoded value at i
//pair may lie anywhere b/n the array so decode it both the ways
//to find the list of prime numbers
// cout<<"Decoded value at :"<<flag+1<<" "<<pair[0][0]<<" "<<pair[0][1]<<endl;
//now create an array of 32 numbers
long res[n+1];
//curing the left sub array
long left=pair[0][0];
long right=pair[0][1];
if(fmod(num[flag+1],pair[0][0])==0){
long t=left;
left=right;
right=t;
}
res[flag+1]=right;
res[flag]=left;
// cout<<"\nFlags are: "<<left<<" "<<right<<endl;
// cout<<"Curing right of "<<flag<<endl;
for (int i = flag+1; i < n; ++i)
{
right=num[i]/right;
res[i+1]=right;
// cout<<res[i]<<endl;
}
// cout<<"\nCuring left of "<<flag<<endl;
for (int i = flag-1; i >-1; i--)
{
left=num[i]/left;
res[i]=left;
// cout<<res[i]<<endl;
}
// sort(res,res+n+1);
set<long> res2;
// cout<<"\nCured Array is:\n";
for (int i = 0; i < n+1; ++i)
{
// cout<<res[i]<<endl;
res2.insert(res[i]);
}
// cout<<"\nSorted Array is:\n";
set<long>::iterator itr;
map<long,char> mp;
int ch=65;
for (itr = res2.begin(); itr!=res2.end();itr++)
{
mp.insert(make_pair(*itr,(char)ch++));
}
cout<<"Case #"<<cse<<": ";
for (int i = 0; i < n+1; ++i)
{
auto it=mp.find(res[i]);
cout<<(*it).second;
}
cout<<endl;
}
return 0;
}