#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> A;
  A.resize(N);
  for (auto &e : A) cin >> e;
  sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  vector<int> B, C;
  B.resize(Q);
  C.resize(Q);
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  int k = 0, l = N - 1, m, count = 0;
  long SumI = 0;
  for (int i = 0; i < Q; i++) {
    count = 0;
    k = 0;
    l = N - 1;
    SumI = 0;
    for (m = k + (l - k) / 2; k < l; m = k + (l - k) / 2) {
      if (B[i] < A[m]) {
        l = m - 1;
      } else {
        if (B[i] > A[m]) {
          k = m + 1;
        } else
          break;
      }
    }
    int m2 = m + 1;
    while (A[m] == B[i] && m >= 0) {
      A[m] = C[i];
      count++;
      m--;
    }
    while (A[m2] == B[i] && m <= N - 1) {
      A[m2] = C[i];
      count++;
      m2++;
    }
    for (auto &e : A) SumI += e;
    cout << SumI << endl;
    if (B[i] < C[i])
      sort(A.begin() + m + 1, A.end());
    else
      sort(A.begin(), A.begin() + m2 - 1);
  }
  return 0;
}
