#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, a, i, j, val;
  long long sum = 0;
  cin >> n;
  int v[n];
  for (i = 0; i < n; i++) {
    cin >> v[i];
  }
  cin >> a;
  int b[a], c[a];
  for (j = 0; j < a; j++) {
    cin >> b[j] >> c[j];
  }
  sum = accumulate(v, v + n, 0);
  for (j = 0; j < a; j++) {
    for (i = 0; i < n; i++) {
      if (v[i] == b[j]) {
        sum = sum - v[i];
        v[i] = c[j];
        sum = sum + v[i];
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
