#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  vector<int> ans(Q);
  for (int i = 0; i < Q; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      if (B.at(i) == vec.at(j)) {
        vec.at(j) = C.at(i);
      }
      sum += vec.at(j);
    }
    cout << sum << endl;
  }
}
