#include <bits/stdc++.h>
int n, q;
int num[123456] = {};
int b[123456], c[123456];
long long s = 0;
int main() {
  scanf("%d", &n);
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    num[a]++;
    s += a;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &b[i], &c[i]);
  }
  for (int i = 0; i < q; i++) {
    s -= b[i] * num[b[i]];
    s += c[i] * num[b[i]];
    printf("%lld\n", s);
    num[c[i]] += num[b[i]];
    num[b[i]] = 0;
  }
  return 0;
}
