The input consists of at least one data set, followed by a line containing only 0.
The first line of a data set contains three space separated integers N P S, where N is the number of DuLLs available, 1 ≤ N ≤ 20, P is the number of programs which can be executed, 1 ≤ P ≤ 9, and S is the number of state transitions recorded, 1 ≤ S ≤ 32.
The next line contains exactly N space separated integers representing the sizes in bytes of each of the DuLLs, 1 ≤ size ≤ 1,000. Each DuLL is implicitly labeled with a letter: ‘A’, ‘B’, ‘C’, ..., possibly extending to ‘T’. Therefore the first integer is the size of ‘A’, the second integer is the size of ‘B’, and so on.
The next P lines contain information about each of the programs, one program per line. Each line contains a single integer representing the size of the program in bytes, 1 ≤ size ≤ 1,000, followed by 1 to N characters representing the DuLLs required by that program. There will be a single space between the size of the program and the DuLL labels, but no spaces between the labels themselves. The order of the labels is insignificant and therefore undefined, but they will all be valid DuLL labels, and no label will occur more than once. Each program is implicitly labeled with an integer: 1, 2, 3, ... possibly extending to 9.
The final line of the data set will contain S space separated integers. Each integer will either be a positive number q, 1 ≤ q ≤ P, indicating that a new execution of program q has begun, or else it will be a negative number –q, 1 ≤ q ≤ P, indicating that a single execution of program q has completed. The transitions are given in the order they occurred. Each is a valid program number; if it is a negative number –q then there will always be at least one instance of program q running.