#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;
int main(int argc, char **argv) {
  i64 n;
  cin >> n;
  vector<i64> as(n);
  map<i64, i64> nums;
  for (int i = 0; i < n; ++i) {
    cin >> as[i];
    auto it = nums.find(as[i]);
    if (it == nums.end())
      nums[as[i]] = 1;
    else
      ++nums[as[i]];
  }
  i64 q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    i64 b, c;
    cin >> b >> c;
    auto it = nums.find(b);
    if (it != nums.end()) {
      auto it2 = nums.find(c);
      if (it2 == nums.end()) {
        nums[c] = it->second;
      } else {
        it2->second += it->second;
      }
      nums.erase(it);
    }
    i64 sum{0};
    for (auto kv : nums) {
      sum += kv.first * kv.second;
    }
    cout << sum << endl;
  }
  return 0;
}
