#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) s += v[i];
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    vector<int>::iterator it;
    int k = 0;
    for (it = find(v.begin(), v.end(), x); it != v.end(); it++) {
      if (*it != x) break;
      *it = y;
      k++;
    }
    s -= (k * (x - y));
    cout << s << endl;
  }
}
