#include <stdio.h>
#include <stdlib.h>


#define ZN_CNT ('z'-'a' + 10)

int zn[ZN_CNT][ZN_CNT];
int N,A;

int subst[ZN_CNT];

void a_mensi_b (int a, int b)
{

  int x;
  
  if (labs(zn[a][b]) != N)
  {
    zn[a][b] = -N;
    zn[b][a] = N;
  
    for (x=0;x<A;x++)
    {
      if(zn[x][b] == N)
      {
        zn[a][x] = -N;
        zn[x][a] = N;
      }  
     
      if(zn[x][a] == -N)
      {
        zn[x][b] = -N;
        zn[b][x] = N;
      }    
    }  
  }

}


int main()
{

  int a,b,K,pos;
  char lsl[60],sl[60], *psl,*plsl,*q;
  char buff[60], slovo [60];
  
  for (a = 0; a < ZN_CNT; a++)
   for (b=0; b < ZN_CNT; b++)
     zn[a][b] = 0;


  gets(buff);
  sscanf(buff,"%d",&N);
  while (N > 0)
  {
    gets (buff);
    sscanf(buff,"%d %d",&A,&K);  
  
    if (K > 0)
      gets(sl);
    psl = sl;
    plsl = lsl;
    
    K--;
    while(K >0)
    {
      K --;
      q = plsl;
      plsl = psl;       
      psl = q;
      
      gets(psl);
      a = 0;
      while ((sl[a] == lsl[a]) && (sl[a] != 0) && (lsl[a] != 0))
        a ++;
        
      if ((sl[a] != 0)&&(lsl[a] != 0))
        a_mensi_b(plsl[a]-'a',psl[a]-'a');  
    }
     
    gets (slovo);    
     
    for (a=0; a < A;a++)
      subst[a] = -1; 
     
    for (a=0;a<A;a++)
    {
      pos = 0;
      for (b=0;b<A;b++)
      {
       
        if (a==b) continue;
        if (zn[a][b] == N)
          pos ++;
          
        if (labs(zn[a][b]) != N)
        {
          pos = -1;
          break;
        }   
      
      }    
      
      if (pos != -1) 
        subst[a] = 'a'+pos;
    }     



      a = 0;
      while (slovo[a] != 0)
      {
        if (slovo[a]-'a' < A)
        {
          slovo[a] = subst[slovo[a]-'a'];
          if (slovo[a] == -1) break;
        }
        a ++;
       }
       
    if (slovo[a] == -1) printf("Message cannot be decrypted.\n"); else
    {
      printf("%s\n",slovo);
    }
    
    N--;
  }

    

return 0;
}

