#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
long long sum = 0;
inline int s(int i) { return cnt[i] * i; }
int main(int argc, char** argv) {
  int n, q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    sum += t;
    cnt[t]++;
  }
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    sum -= s(x) + s(y);
    cnt[y] += cnt[x];
    cnt[x] = 0;
    sum += s(y);
    printf("%lld\n", sum);
  }
  return 0;
}
