#include <bits/stdc++.h>
using namespace std;
int n[100010] = {0};
int main() {
  int N, q, i, s = 0, t, b, c;
  cin >> N;
  for (i = 0; i < N; i++) {
    scanf("%d", &t);
    n[t]++;
    s += t;
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    scanf("%d%d", &b, &c);
    t = c - b;
    s += t * n[b];
    n[c] += n[b];
    n[b] = 0;
    printf("%d\n", s);
  }
  return 0;
}
