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