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