#include <bits/stdc++.h>
int main() {
  int32_t n;
  std::cin >> n;
  std::vector<int32_t> a(n);
  for (int32_t i = 0; i < n; ++i) {
    std::cin >> a.at(i);
  }
  int32_t q;
  std::cin >> q;
  std::vector<int32_t> b(q);
  std::vector<int32_t> c(q);
  for (int i = 0; i < q; ++i) {
    std::cin >> b.at(i) >> c.at(i);
  }
  int64_t sum = 0;
  for (int i = 0; i < q; ++i) {
    if (std::find(a.begin(), a.end(), b.at(i)) == a.end()) {
      std::cout << sum << std::endl;
      continue;
    }
    sum = 0;
    for (int j = 0; j < n; ++j) {
      if (a.at(j) == b.at(i)) {
        a.at(j) = c.at(i);
      }
      sum += a.at(j);
    }
    std::cout << sum << std::endl;
  }
  return 0;
}
