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