#!/usr/bin/env python


import sys


solutionLen = 1000000000
solutionWeight = 1000000000
solution = None

def solve (str, symbols, soln='', solLen = 0, solWeight = 0):
    global solution
    global solutionWeight
    global solutionLen
    if solution == "Too Obvious":
        return
    if len(str) == 0:
        if solLen < solutionLen:
            solution = soln
            solutionLen = solLen
            solutionWeight = solWeight
        elif solWeight < solutionWeight:
            solution = soln
            solutionLen = solLen
            solutionWeight = solWeight
        elif solLen == solutionLen and solWeight == solutionWeight:
            solution = "Too Obvious"
            return 0
    for i in xrange(0,len(symbols)):
        s = symbols[i]
        if str.lower().startswith(s.lower()):
            solve(str[len(s):], symbols, soln + "[" + s + "]", solLen+1, solWeight + i)

def solveIt(str, symbols):
    global solution
    global solutionWeight
    global solutionLen

    solutionLen = 1000000000
    solutionWeight = 1000000000
    solution = None
    solve(str, symbols)
    if solution == None:
        print "No Solution!"
    else:
        print solution

def processCase():
    symbols = []
    numSymbols = int(sys.stdin.readline())
    for i in xrange(0, numSymbols):
        symbols.append(sys.stdin.readline().strip())
    numEquations = int(sys.stdin.readline())
    for i in xrange(0, numEquations):
        solveIt(sys.stdin.readline().strip(), symbols)

if __name__ == "__main__":
    numTests = int(sys.stdin.readline())
    for cases in xrange(0,numTests):
        processCase()
    

#solveIt('banana', symbols1)    
#solveIt('coke', symbols1)    
#solveIt('coke', symbols2)    
#solveIt('ass', symbols2)    
#solveIt('ass', symbols2)    
