#include <bits/stdc++.h>
using namespace std;
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T> >& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
int main() {
  int N;
  cin >> N;
  map<int, int> m;
  vector<int> A(N);
  for (long long i = 0; i < (long long)(N); i++) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (long long i = 0; i < (long long)(Q); i++) {
    cin >> B[i] >> C[i];
  }
  for (long long i = 0; i < (long long)(N); i++) {
    m[A[i]] += 1;
  }
  for (long long i = 0; i < (long long)(Q); i++) {
    m[C[i]] += m[B[i]];
    m[B[i]] = 0;
    int total = 0;
    for (auto i = m.begin(); i != m.end(); ++i) {
      total += i->first * i->second;
    }
    cout << total << endl;
  }
  return 0;
}
