#include <bits/stdc++.h>
int main() {
  int n = 0;
  int data[100001];
  int nannko[1000001];
  for (int i = 0; i < 100000; i++) {
    nannko[i] = 0;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &data[i]);
    nannko[data[i]]++;
  }
  int q;
  scanf("%d", &q);
  long long count = 0;
  int a, move;
  long long disa;
  for (int i = 0; i < 100000; i++) {
    count = count + (long long)nannko[i] * i;
  }
  for (int j = 0; j < q; j++) {
    scanf("%d %d", &a, &move);
    disa = (long long)nannko[a] * (move - a);
    nannko[move] += nannko[a];
    nannko[a] = 0;
    count = count + disa;
    printf("%lld\n", count);
  }
}
