#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const long long INF = 1e18;
using namespace std;
int n, q, b, c, num, i, j;
int a[100003];
long long ans;
int main() {
  cin >> n;
  while (n--) {
    scanf("%d", &num);
    a[num]++;
  }
  for (i = 1; i <= 100000; i++) {
    ans += i * a[i];
  }
  cin >> q;
  while (q--) {
    scanf("%d%d", &b, &c);
    ans += a[b] * (c - b);
    a[c] += a[b];
    a[b] = 0;
    printf("%d\n", ans);
  }
  return 0;
}
