#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::map<std::int64_t, std::int64_t> a;
  for (auto i = 0; i < n; ++i) {
    int val;
    std::cin >> val;
    a[val]++;
  }
  int q;
  std::cin >> q;
  for (auto i = 0; i < q; ++i) {
    int b, c;
    std::cin >> b >> c;
    a[c] += a[b];
    a[b] = 0;
    std::int64_t ans = 0;
    for (const auto& e : a) {
      ans += (e.first * e.second);
    }
    std::cout << ans << std::endl;
  }
}
