#include <bits/stdc++.h>
using namespace std;
int n, q, a[100005], o, x, b, c, i;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
    o += x;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    o += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << o << endl;
  }
  return 0;
}
