#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  multiset<int> A;
  long long second = 0;
  for (int i = 0; i < N; i++) {
    int A_;
    cin >> A_;
    A.insert(A_);
    second += A_;
  }
  int Q;
  cin >> Q;
  int B, C;
  int A_size = N;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    A.erase(B);
    int count = N - A.size();
    for (int j = 0; j < count; j++) {
      A.insert(C);
    }
    second -= (count * (B - C));
    cout << second << endl;
  }
}
