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