#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 (int32_t i = 0; i < q; ++i) {
    std::cin >> b.at(i) >> c.at(i);
  }
  for (int32_t i = 0; i < q; ++i) {
    std::replace(a.begin(), a.end(), b.at(i), c.at(i));
    int64_t sum = std::accumulate(a.begin(), a.end(), 0);
    std::cout << sum << std::endl;
  }
  return 0;
}
