#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  int Q;
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    ll B, C;
    cin >> B >> C;
    for (int j = 0; j < (int)((int)A.size()); j++) {
      if (A[j] == B) A[j] = C;
    }
    ll ans = accumulate(A.begin(), A.end(), 0LL);
    cout << ans << endl;
  }
  return 0;
}
