#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  vector<long long> ans(q);
  sort(a.begin(), a.end());
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int itr = 0;
    while (itr < n) {
      if (a[itr] == b)
        a[itr] = c;
      else if (a[itr] > b)
        break;
      itr++;
    }
    ans[i] = (long long)accumulate(a.begin(), a.end(), 0);
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
