In the factory of ACM Computerized Manufacturing Ltd. (ACM Ltd.), items are manufactured in assembly lines and are given imprinted serial numbers to distinguish them from one another. The serial numbers are generated by a special kind of simplistic multi-function counter machine which generates serial number sequentially in increasing order (, , , and so on).
As the counter machine has multiple functions embedded in its simple design, some substrings are reserved as op-code commands which must not be presented in the machine's serial number output. For example if is a command op-code, then must not be presented in the substring of a serial number - assuming there is no other command op-code, the number sequence would go like this: , , , ..., , , , , ..., , , , , ..., , , , , , ....
This results in a serial number that is different from the actual production batch number recorded in the system. The system does not map the relationship between both numbers and/or record exact serial numbers for each item, this may cause problems when an individual item needs to be tracked (e.g. for a recall or inspection). Given the production batch number of an item, your task is to determine the serial number for that item.
The first line of input contains an integer (T \le 100) denoting the number of testcases. Each testcase begins with an integer (1 \le K \le 10) the number of op-codes in the counter machine, followed by integers ( to digits, with leading zeroes preserved) representing each op-codes.
The second line contains an integer (1 \le N \le 100) the number of requested production batch number, followed by integers representing each production batch number.
For each testcase, print integers the serial numbers of corresponding production batch number. Two adjacent integers are separated by a single space. You may assume that these numbers are fit in signed -bit integer.
Example 1