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