#include <bits/stdc++.h>
using namespace std;
int main() {
  int count[100001] = {0}, pre;
  int N, A, Q, B, C;
  long long int ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    count[A]++;
  }
  for (int i = 1; i <= 100000; i++) {
    ans += i * count[i];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    count[C] += count[B];
    ans += count[B] * C;
    ans -= count[B] * B;
    count[B] = 0;
    cout << ans << endl;
  }
  return 0;
}
