#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 10;
int a[Maxn], n, q;
int main() {
  cin >> n;
  int ai;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &ai);
    a[ai]++;
  }
  cin >> q;
  while (q--) {
    int b, c;
    scanf("%d%d", &b, &c);
    a[c] += a[b];
    a[b] = 0;
    long long sum = 0;
    for (int i = 0; i < Maxn; ++i) {
      sum += a[i] * i;
    }
    cout << sum << endl;
  }
  return 0;
}
