#include <bits/stdc++.h>
int main() {
  int n, q;
  std::cin >> n;
  std::array<int, 100001> dat{};
  std::vector<int> exists;
  for (int i = 0; i < n; i++) {
    int input;
    std::cin >> input;
    if (dat[input] == 0) {
      exists.push_back(input);
    }
    dat[input]++;
  }
  std::sort(exists.begin(), exists.end());
  std::cin >> q;
  long long ans = 0;
  for (int i = 0; i < q; i++) {
    long long from, to;
    std::cin >> from >> to;
    int from_i = -1, to_i = -1;
    for (int i = 0; i < exists.size(); i++) {
      auto& d = exists.at(i);
      long long add;
      add = static_cast<long long>(d) * static_cast<long long>(dat.at(d));
      if (d == to) {
        to_i = i;
      }
      if (d == from) {
        from_i = i;
        d = to;
        add = 0;
        dat.at(to) += dat.at(from);
        dat.at(from) = 0;
      }
      ans += add;
    }
    if (to_i != -1 && from_i != -1) {
      if (from != to) {
        exists.erase(exists.begin() + from_i);
      }
    }
    std::cout << ans << "\n";
    ans = 0;
  }
  return 0;
}
