n, m, x = map(int, input().split()) P = [[] for _ in range(m)] for _ in range(n): a, b = map(int, input().split()) b -= 1 P[b].append(a) lst = [] for p in P: if not p: continue p.sort(reverse = True) p[0] += x lst += p lst.sort(reverse = True) cum = [0] for l in lst: cum.append(cum[-1] + l) k = int(input()) C = list(map(int, input().split())) print(sum(cum[c] for c in C))