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