#include <bits/stdc++.h>
using namespace std;
void bubbleSort(int array[], int array_size) {
  int i, j, k;
  for (i = 0; i < (array_size - 1); i++) {
    for (j = (array_size - 1); j > i; j--) {
      if (array[j] < array[j - 1]) {
        k = array[j];
        array[j] = array[j - 1];
        array[j - 1] = k;
      }
    }
  }
}
int main() {
  int N, A[100001], Q;
  int B[100001], C[100001];
  int sum;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  bubbleSort(A, N);
  for (int i = 0; i < Q; i++) {
    sum = 0;
    for (int j = 0; j < N; j++) {
      if (A[j] = B[i]) {
        A[j] = C[i];
      }
      sum = sum + A[j];
    }
    cout << sum << "\n";
  }
  return 0;
}
