#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    int temp;
    cin >> temp;
    a[temp]++;
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += (i)*a[i];
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    ans += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << ans << endl;
  }
  return 0;
}
