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