#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q, i, sum = 0, x, y;
  cin >> n;
  int ar[100005] = {0};
  for (i = 1; i <= n; i++) {
    cin >> x;
    ar[x]++;
    sum += x;
  }
  cin >> q;
  while (q--) {
    cin >> x >> y;
    sum -= x * ar[x];
    sum += ar[x] * y;
    ar[y] += ar[x];
    ar[x] = 0;
    cout << sum << "\n";
  }
  return 0;
}
