Words and the Periodic Table

Time limit1sMemory limit128 MB

Problem

Given a periodic table and a list of words, write a program that represents each word as a sequence of element symbols taken from the periodic table.

If there are several possible representations, apply the following rules in order:

  1. Choose the one that uses the fewest elements.
  2. If several remain, choose the one with the smallest element mass (the sum of the numbers of the elements used).

If more than one representation still remains after both rules, or if the word cannot be represented by element symbols at all, print Too Obvious.

An element symbol always begins with a single uppercase letter followed by zero or more lowercase letters. Matching a word against element symbols is case-insensitive.

Input

The first line contains the number of test cases.

Each test case is given as follows:

  • The first line contains the number of elements $O$.
  • The next $O$ lines each contain one element symbol.
  • The following line contains the number of words $P$.
  • The next $P$ lines each contain one word.

$O$, $P$, and the length of every word and element symbol are all less than $5000$. Elements are given in order of their atomic number, which starts at $1$ and increases by $1$.

Output

For each word, print the element symbols that represent it, in order. Wrap each element symbol in square brackets [] so they can be told apart. Use the rules in the statement to pick a single representation. If the word cannot be represented, or if the chosen representation is not unique, print Too Obvious.