#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  int q;
  std::cin >> q;
  std::vector<std::pair<int, int>> bc(q);
  for (int i = 0; i < q; ++i) {
    std::cin >> bc[i].first;
    std::cin >> bc[i].second;
  }
  std::vector<long> s(q);
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j < n; ++j) {
      if (a[j] == bc[i].first) {
        a[j] = bc[i].second;
      }
      s[i] += a[j];
    }
  }
  for (int j = 0; j < q; ++j) std::cout << s[j] << std::endl;
}
