#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, q;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  vector<long long int> b, c;
  for (int i = 0; i < (int)(q); i++) {
    long long int s, d;
    cin >> s >> d;
    b.push_back(s);
    c.push_back(d);
  }
  sort(a.begin(), a.end());
  vector<long long int> s;
  for (long long int i = 0; i < q; i++) {
    replace(a.begin(), a.end(), b[i], c[i]);
    long long int sum = accumulate(a.begin(), a.end(), 0LL);
    s.push_back(sum);
  }
  for (auto ans : s) cout << ans << endl;
}
