#include <bits/stdc++.h>
using namespace std;
int main() {
  long long H, W, Q, K, N, x, max = 0, sum = 0;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  cin >> Q;
  vector<long> B(Q), C(Q);
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
    }
    for (int j = 0; j < N; j++) {
      sum += A[j];
    }
    cout << sum << endl;
    sum = 0;
  }
}
