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