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