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