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

typedef vector<int>    vi;
typedef vector<vi>    vvi;
typedef vector<string> vs;

//----------------------------------------------------------------------

map<string,vs> dict;

//----------------------------------------------------------------------

char digit[128];

void prepareDigits () {
  string letters = "e jnq rwx dsy ft am civ bku lop ghz";
  string digits  = "0 111 222 333 44 55 666 777 888 999";
  for( int i=0; i<(int)letters.size(); i++ )
    digit[letters[i]] = digits[i];
}

string number ( string word ) {
  char out[99];
  int n = 0;
  for( int i=0; i<(int)word.size(); i++ )
    if( isalpha(word[i]) )
      out[n++] = digit[ tolower( word[i] )];
  return string( out, out+n );
}

//----------------------------------------------------------------------

string phoneRaw;
char   phoneClean[99];
int p;
vvi prefixes;

void show ( int begin, string soFar ){
  
  //--- Complete? Print it!
  if( begin == p ){
    cout << phoneRaw << ":" << soFar << endl;
    return;
  }
  
  //--- Collect possible extensions.
  set<string> extensions;
  for( int end=begin+1; end<=p; end++ ){
    string phonePart = string( phoneClean+begin, phoneClean+end );
    if( prefixes[end].size()  &&  dict.count( phonePart )){
      vs& exts = dict[phonePart];
      extensions.insert( exts.begin(), exts.end() );
    }
  }
  
  //--- Go on building...
  for( set<string>::iterator ext=extensions.begin(); ext!=extensions.end(); ext++ )
    show( begin + number( *ext ).size(), soFar + " " + *ext );
}

//----------------------------------------------------------------------

int main () {
  prepareDigits();
  int S;
  cin >> S;
  for( int s=1; s<=S; s++ ){
    cout << "Scenario #" << s << ":" << endl;
    
    //--- Read dictionary.
    int n;
    cin >> n;
    dict.clear();
    while( n-- ){
      string word;
      cin >> word;
      dict[ number(word) ].push_back( word );
    }
    
    //--- Process phone numbers.
    cin >> n;
    while( n-- ){
      
      //--- Read and clean the number.
      cin >> phoneRaw;
      p = 0;
      for( int i=0; i<(int)phoneRaw.size(); i++ )
	if( isdigit( phoneRaw[i] ))
	  phoneClean[p++] = phoneRaw[i];
      
      //--- Init the DP.
      prefixes = vvi( p+1 );
      prefixes[p].push_back( 0 );
      
      //--- Dance the funky DP...
      for( int begin=p-1; begin>=0; begin-- ){
	for( int end=begin+1; end<=p; end++ ){
	  if( prefixes[end].size()  &&  dict.count( string( phoneClean+begin, phoneClean+end )))
	    prefixes[begin].push_back( end - begin );
	}
      }
      
      //--- Answer.
      if( ! prefixes[0].size() )
	cout << phoneRaw << " cannot be encoded." << endl;
      else
	show( 0, "" );
    }
    cout << endl;
  }
}
