#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int h[100005] = {0};
  int s = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    s += x;
    h[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    if (l > r)
      s -= ((l - r) * h[l]);
    else
      s += ((r - l) * h[l]);
    h[r] += h[l];
    h[l] -= h[r];
    cout << s << endl;
  }
  return 0;
}
