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