#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  vector<int> temp(n);
  for (int& i : temp) {
    cin >> i;
    sum += i;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (temp[i] == a) {
        sum += b - temp[i];
        temp[i] = b;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
