#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, a, b, c;
  long long ans;
  vector<int> A(100001, 0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    A[a]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &b, &c);
    A[c] += A[b];
    A[b] = 0;
    ans = 0;
    for (int i = 0; i < 100001; i++) {
      ans = ans + A[i] * i;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
