#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, t, sum = 0, k, co;
  cin >> n;
  vector<long long> v(n);
  for (i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  cin >> t;
  vector<pair<long long, long long>> p(t);
  for (i = 0; i < t; i++) {
    long long x, y;
    cin >> x >> y;
    p[i] = make_pair(x, y);
  }
  sort(v.begin(), v.end());
  for (i = 0; i < t; i++) {
    co = 0;
    for (k = 0; k < n; k++) {
      if (v[k] == p[i].first) {
        co++;
        v[k] = p[i].second;
      }
    }
    sum -= co * p[i].first;
    sum += co * p[i].second;
    cout << sum << "\n";
  }
  if (0) {
    for (auto z : p) {
      cout << z.first << " " << z.second << "\n";
    }
  }
}
