#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ar[100000];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  int q;
  cin >> q;
  int cnt[100001];
  memset(cnt, 0, sizeof(cnt));
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cnt[ar[i]]++;
    sum += ar[i];
  }
  while (q--) {
    int p, q;
    cin >> p >> q;
    if (cnt[p] != 0) {
      sum -= cnt[p] * p;
      sum += cnt[p] * q;
      cnt[q] += cnt[p];
      cnt[p] = 0;
      cout << sum << endl;
    }
  }
  return 0;
}
