#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, *A, *B, *C;
  cin >> N;
  A = new int[N];
  unordered_map<int, int> map;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    map[A[i]] += 1;
  }
  cin >> Q;
  B = new int[Q];
  C = new int[Q];
  for (int i = 0; i < Q; ++i) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; ++i) {
    int64_t S = 0;
    map[C[i]] += map[B[i]];
    map[B[i]] = 0;
    for (const auto& m : map) {
      S += m.first * m.second;
    }
    cout << S << endl;
  }
  return 0;
}
