#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  unordered_map<int, int> valCount;
  for (int i = 0; i < (int)(N); i++) {
    int A;
    cin >> A;
    auto it = valCount.find(A);
    if (it == valCount.end()) {
      valCount.insert(pair<int, int>(A, 1));
    } else {
      it->second += 1;
    }
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    int B, C;
    cin >> B >> C;
    auto itBef = valCount.find(B);
    if (itBef != valCount.end()) {
      auto itAft = valCount.find(C);
      if (itAft == valCount.end()) {
        valCount.insert(pair<int, int>(C, itBef->second));
        valCount.erase(itBef);
      } else {
        itAft->second += itBef->second;
        valCount.erase(B);
      }
    }
    long int sum = 0;
    for (const auto& it : valCount) {
      sum += it.first * it.second;
    }
    cout << sum << endl;
  }
  return 0;
}
