#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
int n, q;
int a[N];
int cnt[N];
long long ans[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    ans[0] += a[i];
    cnt[a[i]]++;
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int b, c;
    scanf("%d %d", &b, &c);
    ans[i] = ans[i - 1];
    ans[i] -= cnt[b] * b;
    cnt[c] += cnt[b];
    ans[i] += cnt[b] * c;
    cnt[b] = 0;
  }
  for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]);
  return 0;
}
