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