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