#include <bits/stdc++.h>
int main(void) {
  int64_t N;
  std::cin >> N;
  int64_t dp[100010] = {};
  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    std::cin >> a;
    dp[a]++;
  }
  int64_t ans = 0;
  for (int64_t i = 1; i <= N; ++i) {
    if (dp[i] == 0) continue;
    ans += i * dp[i];
  }
  int64_t Q;
  std::cin >> Q;
  for (int64_t i = 0; i < Q; ++i) {
    int64_t b, c;
    std::cin >> b >> c;
    int64_t num = dp[b];
    dp[c] += dp[b];
    dp[b] = 0;
    ans -= num * b;
    ans += num * c;
    std::cout << ans << std::endl;
  }
  return 0;
}
