#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int input;
  for (int i = 0; i < n; i++) {
    cin >> input;
    v.push_back(input);
  }
  sort(v.begin(), v.end());
  int q;
  int b, c;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    replace(v.begin(), v.end(), b, c);
    int sum = accumulate(v.begin(), v.end(), 0);
    cout << sum << endl;
  }
}
