#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, q, a, b, c;
  cin >> n;
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  cin >> q;
  sort(v.begin(), v.end());
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    for (int j = 0; j < n; j++) {
      if (v.at(j) == b) {
        v.at(j) = c;
      } else if (v.at(j) > c) {
        break;
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << "\n";
  }
  return 0;
}
