// Arup Guha
// 9/19/2012
// Solution to 2009 MCPC Problem C: DuLL

import java.util.*;

public class c {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		// Go through all cases.
		while (n != 0) {

			// DuLL information.
			int p = stdin.nextInt();
			int s = stdin.nextInt();
			int[] dllSize = new int[n];
			for (int i=0; i<n; i++)
				dllSize[i] = stdin.nextInt();

			// Program information.
			prog[] myProgs = new prog[p];
			for (int i=0; i<p; i++) {
				int a = stdin.nextInt();
				String b = stdin.next();
				myProgs[i] = new prog(a, b);
			}

			int maxmem = 0;

			// Keeps track of who is running...
			int[] freq = new int[p];
			boolean[] libs = new boolean[n];

			// Simulate.
			for (int i=0; i<s; i++) {

				// Get program.
				int progNum = stdin.nextInt();

				// Starting a program.
				if (progNum > 0) {

					// Set up libraries to be true. for this program.
					freq[progNum-1]++;
					Arrays.fill(libs, false);
					for (int j=0; j<p; j++) {
						if (freq[j] > 0) {
							for (int k=0; k<myProgs[j].dlls.size(); k++)
								libs[myProgs[j].dlls.get(k)] = true;
						}
					}

					// Add in memory totals.
					int curmem = 0;
					for (int j=0; j<p; j++)
						curmem += (freq[j]*myProgs[j].memory);
					for (int j=0; j<n; j++)
						if (libs[j])
							curmem += dllSize[j];

					// Update if this needs more than previous settings.
					if (curmem > maxmem)
						maxmem = curmem;
				}

				// Execute completing a program.
				else {

					// Mark this program as done and process libs array.
					freq[-progNum-1]--;
					Arrays.fill(libs, false);
					for (int j=0; j<p; j++) {
						if (freq[j] > 0) {
							for (int k=0; k<myProgs[j].dlls.size(); k++)
								libs[myProgs[j].dlls.get(k)] = true;
						}
					}

				}

			}

			// Print result.
			System.out.println(maxmem);
			n = stdin.nextInt();
		}
	}
}

class prog {

	public int memory;
	public ArrayList<Integer> dlls;

	public prog(int mem, String list) {

		memory = mem;
		dlls = new ArrayList<Integer>();
		for (int i=0; i<list.length(); i++)
			dlls.add(list.charAt(i) - 'A');
	}
}