#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n, q, sum = 0;
  cin >> n;
  vector<int> cnt(100001);
  for (int i = 0; i < n; i++) {
    cin >> a;
    cnt[a]++;
    sum += a;
  }
  cin >> q;
  vector<int> adSum(q);
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    adSum[i] = (c - b) * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  for (int i = 0; i < q; i++) {
    sum += adSum[i];
    cout << sum << endl;
  }
  return 0;
}
