#include <bits/stdc++.h>
using namespace std;
int num[(int)1e5 + 1];
pair<int, int> trans[(int)1e5];
int main(void) {
  for (int i = 0; i <= (int)1e5; i++) {
    num[i] = 0;
  }
  int N;
  cin >> N;
  for (int n = 0; n < N; n++) {
    int tmp;
    cin >> tmp;
    num[tmp] += 1;
  }
  int Q;
  cin >> Q;
  long long int ans = 0;
  for (int n = 1; n <= (int)1e5; n++) {
    ans += n * num[n];
  }
  for (int q = 0; q < Q; q++) {
    int b, c;
    cin >> b >> c;
    trans[q] = make_pair(b, c);
  }
  for (int q = 0; q < Q; q++) {
    int b, c;
    b = trans[q].first;
    c = trans[q].second;
    ans = ans - b * num[b] + c * num[b];
    num[c] += num[b];
    num[b] = 0;
    cout << ans << endl;
  }
  return 0;
}
