#include using namespace std; long long n, k, m, x, c, s, t, z = 0; vector a[200000]; vector b, d; int main() { cin >> n >> m >> x; for (int i = 0; i < n; i++) { cin >> s >> t; t--; a[t].push_back(s); } for (int i = 0; i < m; i++) { if (a[i].size() > 0) { sort(a[i].begin(), a[i].end()); a[i].back() += x; for (long long j : a[i]) b.push_back(j); } } sort(b.begin(), b.end(), greater()); d.push_back(b[0]); for (int i = 1; i < b.size(); i++) d.push_back(d.back() + b[i]); cin >> k; for (int i = 0; i < k; i++) { cin >> c; if(c > 0) z += d[c - 1]; } cout << z << endl; }