#include <bits/stdc++.h>
int main() {
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  long long sum = 0;
  for (long long i = 0; i < N; i++) {
    sum += A[i];
  }
  long long Q;
  std::cin >> Q;
  std::vector<long long> sum_list(Q);
  for (long long i = 0; i < Q; i++) {
    std::sort(A.begin(), A.end(), std::greater<long long>());
    long long B, C;
    int value_check = 0;
    std::cin >> B;
    std::cin >> C;
    long long diff = C - B;
    long long start = 0;
    long long end = N - 1;
    long long point = -1;
    while (start <= end) {
      long long middle = (start + end) / 2;
      if (B > A[middle]) {
        end = middle - 1;
      } else if (B < A[middle]) {
        start = middle + 1;
      } else {
        point = middle;
        break;
      }
    }
    if (point == -1) {
      sum_list[i] = sum;
    } else {
      while (true) {
        if ((point - 1) < 0) {
          break;
        } else if (B != A[point - 1]) {
          break;
        } else {
          point--;
        }
      }
      while (true) {
        if (A[point] == B) {
          sum += diff;
          A[point] = C;
          point++;
        } else {
          sum_list[i] = sum;
          break;
        }
      }
    }
  }
  for (long long i = 0; i < Q; i++) {
    std::cout << sum_list[i] << std::endl;
  }
}
