#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[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[i] >> c[i];
  }
  for (int32_t i = 0; i < q; ++i) {
    int64_t sum = 0;
    for (int32_t j = 0; j < n; ++j) {
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
      sum += a[j];
    }
    std::cout << sum << std::endl;
  }
  return 0;
}
