#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  long A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + (sizeof(A) / sizeof(A[0])));
  long long Q;
  cin >> Q;
  long long index;
  long long B[N], C[N];
  for (int n = 0; n < Q; n++) {
    cin >> B[n] >> C[n];
  }
  for (int n = 0; n < Q; n++) {
    index = 0;
    while (A[index] <= B[n] and index < N) {
      if (A[index] == B[n]) {
        A[index] = C[n];
      }
      index++;
    }
    cout << accumulate(A, A + (sizeof(A) / sizeof(A[0])), 0) << endl;
    sort(A, A + (sizeof(A) / sizeof(A[0])));
  }
}
