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