#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k, sum = 0;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
    sum += x;
  }
  cin >> k;
  while (k--) {
    int x, y;
    cin >> x >> y;
    for (int i = 0; i < n; i++) {
      if (a[i] == x) {
        sum -= a[i];
        sum += y;
        a[i] = y;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
