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