#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main(void) {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> vi(n);
  for (int i = 0; i < n; ++i) {
    cin >> vi[i];
  }
  sort((vi).begin(), (vi).end());
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int ans = 0, b, c;
    cin >> b >> c;
    replace((vi).begin(), (vi).end(), b, c);
    ans = accumulate((vi).begin(), (vi).end(), 0);
    cout << ans << endl;
  }
  return 0;
}
