#include <bits/stdc++.h>
using namespace std;
int read() {
  int r = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    r = (r << 1) + (r << 3) + c - '0';
    c = getchar();
  }
  return r * f;
}
int cnt[10005], n, q;
long long ans;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    ans += x;
    cnt[x]++;
  }
  q = read();
  for (int i = 1; i <= q; i++) {
    int b = read(), c = read();
    ans -= 1ll * cnt[b] * b;
    ans += 1ll * cnt[b] * c;
    printf("%lld\n", ans);
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  return 0;
}
