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