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