import itertools import collections import math def main(): N,M,X=map(int,input().split( )) A=list(range(N)) B=list(range(N)) for num in range(N): A[num],B[num]=map(int,input().split( )) K=int(input()) S=list(range(N)) T=list(range(N)) C= [int(i) for i in input().split()] Q=list(itertools.permutations(T)) F=list(range(math.factorial(N))) U=list(range(K)) E=0 for j in range(K): if C[j]==0: U[j]=0 else: for num in range(math.factorial(N)): for p in range(N): T[p] = B[Q[num][p]] for NUM in range(C[j]): E=E + A[Q[num][NUM]] F[num]=E + len(collections.Counter(T[0:C[j]])) * X E=0 U[j]= max(F) h=0 for w in range(K): h=h + U[w] print(h) if __name__ == '__main__': main()