#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  static int A[100001];
  int B, C;
  static long long S[100001];
  int tempA;
  for (int i = 0; i < N; i++) {
    cin >> tempA;
    A[tempA]++;
    S[0] += tempA;
  }
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    cin >> B >> C;
    long long sum = 0;
    sum = S[i - 1] + (C - B) * A[B];
    int tempB = A[B];
    A[B] = 0;
    A[C] += tempB;
    printf("%lld", sum);
    S[i] = sum;
  }
  return 0;
}
