// Задача "Плейлист"
// 9-ая Интернет-олимпиада сезона 2007-2008, базовый уровень
// Автор задачи: Сергей Поромов, poromov@rain.ifmo.ru
// Автор решения: Сергей Поромов, poromov@rain.ifmo.ru

import java.io.*;
import java.util.*;

public class music_sp_bug implements Runnable {

	public static void main(String[] args) {
		new Thread(new music_sp_bug()).run();
	}

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;

	PrintWriter out;

	StringTokenizer st;

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean e, String s) {
		if (!e) {
			throw new Error("Assertion failure " + s);
		}
	}

	private static final String FILENAME = "music";

	public void solve() throws IOException {
		br = new BufferedReader(new FileReader(FILENAME + ".in"));
		out = new PrintWriter(FILENAME + ".out");
		int n = nextInt();
		myAssert(n >= 1 && n <= 1000, "1");
		String[] name = new String[n];
		int[] len = new int[n];
		int[] rating = new int[n];
		for (int i = 0; i < n; i++) {
			name[i] = nextToken();
			len[i] = nextInt();
			myAssert(0 < len[i] && len[i] <= 30 * 60, "2");
			myAssert(name[i].length() <= 50, "3");
			for (int j = 0; j < name[i].length(); j++) {
				myAssert(name[i].charAt(j) >= 'a' && name[i].charAt(j) <= 'z', "4");
			}
		}
		int m = nextInt();
		int k = nextInt();
		myAssert(m >= 1 && m <= 1000, "5");
		myAssert(k >= 1 && k <= 1000, "6");
		String[] play = new String[m];
		for (int i = 0; i < m; i++) {
			play[i] = br.readLine();
		}
		int[] times = new int[k];
		for (int i = 0; i < k; i++) {
			times[i] = nextInt();
		}
		int j = 0;
		int curtime = 0;
		for (int i = 0; i < m; i++) {
			int ind = -1;
			for (int ii = 0; ii < n; ii++) {
				if (name[ii].equals(play[i])) {
					ind = ii;
				}
			}
			myAssert(ind != -1, "7");
			if (j < k && curtime + len[ind] > times[j]) {
				rating[ind]--;
				curtime = times[j];
				j++;
			} else {
				rating[ind]++;
				curtime += len[ind];
			}
		}
		for (int i = 0; i < n; i++) {
			out.print(rating[i] + " ");
		}
		out.close();
	}
}
