#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, B, C;
  int ans_tmp = 0;
  std::cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  std::cin >> Q;
  vector<int> ans(Q);
  for (int i = 0; i < Q; i++) {
    std::cin >> B >> C;
    for (int j = 0; j < N; j++) {
      if (A[j] == B) {
        A[j] = C;
      }
      ans_tmp = ans_tmp + A[j];
    }
    ans[i] = ans_tmp;
    ans_tmp = 0;
  }
  for (int i = 0; i < Q; i++) {
    std::cout << ans[i] << "\n";
  }
}
