#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q, b, c;
  cin >> N;
  vector<long long> vec(N);
  for (long long i = 0; i < N; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    cin >> b >> c;
    replace(vec.begin(), vec.end(), b, c);
    cout << accumulate(vec.begin(), vec.end(), 0) << endl;
  }
}
