#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int A[100001];
  int N, Q, temp, B, C, sum = 0;
  cin >> N;
  memset(A, 0, sizeof(A));
  for (int i = 0; i < N; i++) {
    cin >> temp;
    A[temp]++;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    A[C] += A[B];
    A[B] = 0;
    for (int j = 1; j < 100001; j++) {
      if (A[j] != 0) {
        sum += j * A[j];
      }
    }
    cout << sum << "\n";
    sum = 0;
  }
  return 0;
}
