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