#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;
    for (long long j = 0; j < N; j++) {
      if (A[j] == B) {
        value_check = 1;
        A[j] = C;
        sum += diff;
      } else {
        if (value_check == 1) {
          break;
        }
      }
    }
    sum_list[i] = sum;
  }
  for (long long i = 0; i < Q; i++) {
    std::cout << sum_list[i] << std::endl;
  }
}
