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