#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> M;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (M.find(a) == M.end()) {
      M[a] = 1;
    } else {
      M[a]++;
    }
  }
  int Q;
  cin >> Q;
  string result;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    if (M.find(B) != M.end()) {
      if (M.find(C) != M.end()) {
        M[C] += M[B];
        M[B] = 0;
      } else {
        M[C] = M[B];
        M[B] = 0;
      }
    }
    long long r = 0;
    for (auto& it : M) {
      r += it.first * it.second;
    }
    result += to_string(r) + "\n";
  }
  cout << result;
  return 0;
}
