#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 1;
int cnt[mxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q, tmp, b, c;
  long long sum = 0;
  memset(cnt, 0, sizeof(cnt));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    cnt[tmp]++;
    sum += tmp;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    sum -= cnt[b] * b;
    sum += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}
