#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v(100006, 0);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    sum += x;
    v[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    if (v[x] > 0) {
      sum -= x * v[x];
      sum += v[x] * y;
      v[y] += v[x];
      v[x] = 0;
    }
    cout << sum << endl;
  }
}
int main() {
  solve();
  return 0;
}
