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