#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, v[100000], q, b, c, s = 0, i, aux;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> aux;
    v[aux]++;
    s += aux;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    s += (c - b) * v[b];
    v[c] += v[b];
    v[b] = 0;
    cout << s << endl;
  }
  return 0;
}
