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