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