#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 < N; i++) cin >> A.at(i);
  cin >> Q;
  vector<long long> ans(Q);
  for (long long i = 0; i < Q; i++) {
    sort(A.begin(), A.end());
    ans.at(i) = accumulate(A.begin(), A.end(), 0);
    long long B, C;
    cin >> B >> C;
    long long j = 0;
    while (j < N) {
      if (A.at(j) < B)
        j++;
      else if (A.at(j) == B) {
        ans.at(i) = ans.at(i) - B + C;
        A.at(j) = C;
        j++;
      } else
        break;
    }
  }
  for (long long i = 0; i < Q; i++) cout << ans.at(i) << endl;
}
