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