#include #define rep(i,n) for(int i=0; i<(int)(n); i++) using namespace std; using LL = long long; int main(){ int N, M; LL X; cin >> N >> M >> X; vector V(N), G(N); rep(i,N) cin >> V[i] >> G[i]; int K; cin >> K; vector p(K); rep(i,K) cin >> p[i]; if(N >= 10){ cout << 0 << endl; return 0; } vector per(N); LL ans = 0; rep(i,N) per[i] = i; do{ LL res = 0; rep(i,K){ LL kind = 0; vector solved(M); rep(j,p[i]){ int num = per[j]; res += V[num]; if(!solved[G[num]]) kind++; solved[G[num]] = true; } res += X * kind; } ans = max(ans,res); }while(next_permutation(per.begin(),per.end())); cout << ans << endl; return 0; }