#include <bits/stdc++.h>
using namespace std;
multiset<int> test;
using namespace std;
int n, k;
const int N = 1e5 + 10;
vector<int> a2;
int a[N];
int main() {
  cin >> n;
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    a2.push_back(a[i]);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    while (find(a2.begin(), a2.end(), b) != a2.end()) {
      a2[b] = c;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += a2[i];
    }
    cout << sum << endl;
  }
  return 0;
}
