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