#include <bits/stdc++.h>
using namespace std;
using Lint = long long;
using P = pair<int, int>;
using V = vector<int>;
using M = map<int, int>;
using S = set<int>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  V a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  int q;
  cin >> q;
  P bc[q];
  for (int i = 0; i < q; ++i) {
    cin >> bc[i].first;
    cin >> bc[i].second;
  }
  sort((a).begin(), (a).end());
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j < (int)(n); j++) {
      if (bc[i].first == a[j]) a[j] = bc[i].second;
    }
    int sum = 0;
    for (int i = 0; i < (int)(n); i++) sum += a[i];
    cout << (sum) << endl;
  }
}
