#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  int B[Q], C[Q];
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  int sum = 0;
  for (int i = 0; i < Q; i++) {
    sum = 0;
    for (int j = 0; j < N; j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
        sum = sum + A[j];
      } else {
        sum = sum + A[j];
      }
    }
    cout << sum << endl;
  }
  return 0;
}
