#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
string A="1000";
string B="0100";
string C="0010";
string D="0001";
int main()
{
int T,n;
cin>>T>>n;
double sfeq=100.0/n;
const int qs=n;
string cq;
cin>>cq;
while(T--){
string id2,type,q[qs];
cin>>id2>>type;
for(int i=1;i<=n;i++) cin>>q[i];
cout<<endl;
long long id10=0;
for(int i=0;i<id2.size();i++){
if(id2[i]=='1') id10+=pow(2,15-i);
}
if(id10>=1&&id10<=10000){
cout<<"ID: "<<id10<<endl;
if(type[0]==type[1]) cout<<"Type Incorrect\n";
else cout<<"Type Correct\n";
double score=0;
int AC=0;
for(int i=1;i<=n;i++){
if(cq[i-1]=='A'){
if(q[i]==A) AC++;
}
else if(cq[i-1]=='B'){
if(q[i]==B) AC++;
}
else if(cq[i-1]=='C'){
if(q[i]==C) AC++;
}
else if(cq[i-1]=='D'){
if(q[i]==D) AC++;
}
}
score=AC*sfeq;
printf("%.1lf\n",score);
}
else cout<<"Wrong ID\n";
}
return 0;
}
RT