#include <bits/stdc++.h>
using Ps = std::vector<std::pair<long, long>>;
void solve(long n, const std::vector<long>& values, long q, const Ps& ps) {
  std::vector<long> counts(100001, 0);
  long sum = 0;
  for (auto v : values) {
    ++counts[v];
    sum += v;
  }
  for (auto& p : ps) {
    const auto src = p.first;
    const auto dst = p.second;
    const auto d = dst - src;
    const auto src_count = counts[src];
    sum += d * src_count;
    counts[dst] += src_count;
    std::cout << sum << std::endl;
  }
}
int main() {
  long n;
  std::cin >> n;
  std::vector<long> values(n);
  for (auto& v : values) {
    std::cin >> v;
  }
  long q;
  std::cin >> q;
  Ps ps(q);
  for (auto& p : ps) {
    std::cin >> p.first >> p.second;
  }
  std::cout << std::setprecision(20);
  solve(n, values, q, ps);
}
