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