from sys import stdin from heapq import heappush, heappop n, m, x, *indata = map(int, stdin.read().split()) offset = 0 hq = [] janru = [0 for i in range(n)] appeared = [0 for i in range(n)] for i in range(n): s, t = indata[offset + 2*i],indata[offset + 2*i+1] heappush(hq, (-(s+x),i)) janru[i] = t used = [0 for i in range(m+1)] manzoku = [0] while hq: score, ind = heappop(hq) score = -score if (appeared[ind] == 0) & (used[janru[ind]] >= 1): heappush(hq,(-score+x,ind)) appeared[ind] = 1 else: kari = manzoku[-1] + score used[janru[ind]] += 1 manzoku.append(kari) ans = 0 offset += n * 2 k = indata[offset] for i in range(1,k+1): ans += manzoku[indata[offset+i]] print("{}".format(ans))