#include <bits/stdc++.h>
using namespace std;
int has[100010];
int long long n;
int main() {
  int n, q, b, c;
  long long sum, a;
  while (scanf("%d", &n) != EOF) {
    sum = 0;
    for (int i = 0; i <= 100000; i++) has[i] = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      has[a]++;
      sum += a;
    }
    scanf("%d", &q);
    while (q--) {
      scanf("%d %d", &b, &c);
      sum -= b * has[b];
      sum += c * has[b];
      has[c] += has[b];
      has[b] = 0;
      printf("%lld\n", sum);
    }
  }
  return 0;
}
