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