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