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