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