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