#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, q;
  cin >> n;
  long long int a[n], t = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    t += a[i];
  }
  sort(a, a + n);
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    long long int x, y;
    cin >> x >> y;
    for (long long int j = 0; j < n; j++) {
      if (a[j] == x) {
        t = t + y - x;
        a[j] = y;
      }
      if (a[j - 1] == x && a[j] != x) break;
    }
    sort(a, a + n);
    cout << t << "\n";
  }
  return 0;
}
