#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
int main() {
  ll N, Q;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
  }
  cin >> Q;
  vector<ll> B(Q);
  vector<ll> C(Q);
  vector<ll> S(Q, 0);
  for (ll i = 0; i < Q; ++i) {
    cin >> B[i] >> C[i];
    for (ll j = 0; j < N; ++j) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
      S[i] += A[j];
    }
  }
  for (ll i = 0; i < Q; ++i) {
    cout << S[i] << endl;
  }
  return 0;
}
