#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  vector<int> A;
  int Q;
  vector<vector<int>> BC;
  cin >> N;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  cin >> Q;
  for (int i = 0, i_len = (Q); i < i_len; ++i) {
    int b, c;
    cin >> b >> c;
    BC.push_back({b, c});
  }
  sort(A.begin(), A.end());
  for (int q = 0, q_len = (Q); q < q_len; ++q) {
    int left = 0;
    int right = A.size() - 1;
    while (right >= left) {
      int mid = left + (right - left) / 2;
      if (A[mid] == BC[q][0])
        A[mid] = BC[q][1];
      else if (A[mid] > BC[q][0])
        right = mid - 1;
      else if (A[mid] < BC[q][0])
        left = mid + 1;
    }
    int sum = 0;
    for (int n = 0, n_len = (N); n < n_len; ++n) {
      sum += A[n];
    }
    cout << sum << endl;
  }
  return 0;
}
