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