#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long ans = 0;
int n, q, cnt[MAXN] = {0};
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1, x; i <= n; ++i) {
    cin >> x;
    ++cnt[x];
    ans += x;
  }
  cin >> q;
  for (int i = 1, b, c; i <= q; ++i) {
    cin >> b >> c;
    ans = ans - cnt[b] * b + cnt[b] * c;
    cnt[c] += cnt[b], cnt[b] = 0;
    cout << ans << '\n';
  }
  return 0;
}
