#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n, q;
  cin >> n;
  int cnt[100010] = {};
  int tmp;
  for (int i = 0; i < (n); i++) {
    cin >> tmp;
    cnt[tmp]++;
  }
  int sum = 0;
  for (int i = 0; i < (100000); i++) {
    sum += cnt[i + 1] * (i + 1);
  }
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < (q); i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < (q); i++) {
    int b_cnt = cnt[b[i]];
    cnt[b[i]] = 0;
    cnt[c[i]] += b_cnt;
    sum -= b_cnt * b[i];
    sum += c[i] * b_cnt;
    cout << sum << endl;
  }
  return 0;
}
