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