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