#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int value[100001];
  int n;
  cin >> n;
  for (int i = 0; i < 100001; i++) {
    value[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    value[tmp]++;
  }
  int q;
  cin >> q;
  ll ans = 0;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (i == 0) {
      value[c] += value[b];
      value[b] = 0;
      for (int i = 1; i < 100001; i++) {
        ans += value[i] * i;
      }
      cout << ans << endl;
    } else {
      ans += c * value[b];
      value[c] += value[b];
      ans -= b * value[b];
      value[b] = 0;
      cout << ans << endl;
    }
  }
}
