#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  int Q;
  cin >> Q;
  int B[Q];
  int C[Q];
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < Q; i++) {
    int hi = N;
    int lo = -1;
    while (hi - lo > 1) {
      int mid = (hi + lo) / 2;
      if (A[mid] >= B[i])
        hi = mid;
      else
        lo = mid;
    }
    int index = hi;
    while (A[index] == B[i]) {
      A[index] = C[i];
      sum += (C[i] - B[i]);
      index++;
    }
    cout << sum << endl;
    sort(A.begin(), A.end());
  }
}
