#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> idx[100001];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    idx[a[i]].push_back(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    for (int j = 0; j < idx[b].size(); j++) {
      a[idx[b][j]] = c;
      idx[c].push_back(idx[b][j]);
      sum -= b;
      sum += c;
    }
    idx[b].clear();
    cout << sum << '\n';
  }
  return 0;
}
