#include <bits/stdc++.h>
using namespace std;
int cnt[100005], a[100005];
long long ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    ans += a[i];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int x, y;
    cin >> x >> y;
    cnt[y] += cnt[x];
    ans -= cnt[x] * x;
    ans += cnt[x] * y;
    cnt[x] = 0;
    cout << ans << endl;
  }
  return 0;
}
