#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  vector<int64_t> S(Q + 1);
  S.at(0) = sum;
  for (int j = 1; j < Q + 1; j++) {
    int b, c;
    cin >> b >> c;
    int count = 0;
    int min = N;
    int max = N - 1;
    for (int i = 0; i < N; i++) {
      if (A.at(i) == b) {
        min = i;
        A.at(i) = c;
        if (min < N - 1) {
          for (int k = min + 1; k < N; k++) {
            if (A.at(k) == b)
              A.at(k) = c;
            else {
              max = k - 1;
              break;
            }
          }
        }
        break;
      }
    }
    S.at(j) = S.at(j - 1) + (max - min + 1) * (c - b);
    cout << S.at(j) << endl;
  }
  return 0;
}
