#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    long long dif = 0;
    long long x, y;
    cin >> x >> y;
    long long raz = y - x;
    for (int i = 0; i < n; i++) {
      if (a[i] == x) {
        a[i] = y;
        dif += raz;
      }
    }
    sum += dif;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1;
  for (; t; t--) {
    solve();
  }
  return 0;
}
