#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n;
  scanf(" %lld", &n);
  long long sum = 0;
  int num[100001];
  for (int i = 0; i < 10001; i++) num[i] = 0;
  vector<char> p(n);
  for (long long i = 0; i < n; i++) {
    scanf(" %lld", &p[i]);
    sum += p[i];
    num[p[i]]++;
  }
  long long q;
  scanf(" %lld", &q);
  long long b, c;
  for (long long i = 0; i < q; i++) {
    scanf("%lld %lld", &b, &c);
    sum += num[b] * (c - b);
    num[c] += num[b];
    num[b] = 0;
    printf("%lld\n", sum);
  }
}
