#include "bits/stdc++.h" #define int long long using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = 998244353; void solve() { int N, M, X; cin >> N >> M >> X; vectorA(N), B(N); vector>t(M); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; B[i]--; t[B[i]].push_back(A[i]); } for (int i = 0; i < M; i++)sort(t[i].rbegin(), t[i].rend()); vectorV; for (int i = 0; i < M; i++) { int now = 0; for (auto x : t[i]) { if (now == 0)V.push_back(x + X); else V.push_back(x); now++; } } sort(V.rbegin(), V.rend()); vectorsum(N + 1); for (int i = 0; i < N; i++)sum[i + 1] = sum[i] + V[i]; int K; cin >> K; int ans = 0; for (int i = 0; i < K; i++) { int C; cin >> C; ans += sum[C]; } cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }