#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    sort(v.begin(), v.end());
    int B, C;
    cin >> B >> C;
    long long int S = 0;
    int j = 0;
    if (v.at(N - 1) >= B) {
      while (v.at(j) != B) {
        j++;
      }
      while (j < N && v.at(j) == B) {
        v.at(j) = C;
        j++;
      }
    }
    for (int k = 0; k < N; k++) {
      S += v.at(k);
    }
    cout << S << endl;
  }
}
