#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N, Q;
  cin >> N;
  long long A[N];
  for (long long i = 0; i < (long long)(N); i++) {
    cin >> A[i];
  }
  cin >> Q;
  long long B, C;
  for (long long i = 0; i < (long long)(Q); i++) {
    cin >> B >> C;
    long long ans = 0;
    for (long long j = 0; j < (long long)(N); j++) {
      if (A[j] == B) {
        A[j] = C;
      }
      ans += A[j];
    }
    cout << ans << endl;
  }
  return 0;
}
