#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> m;
  int n;
  cin >> n;
  int *arr = new int[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int q;
  cin >> q;
  for (int z = 0; z < q; z++) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (arr[i] == b) {
        sum = sum - arr[i] + c;
        arr[i] = c;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
