#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)n; i++) {
    cin >> a.at(i);
  }
  ll current = accumulate(a.begin(), a.end(), 0);
  cin >> q;
  for (int i = 0; i < (int)q; i++) {
    int b, c;
    ll ans;
    cin >> b >> c;
    auto temp = a.begin();
    while (true) {
      auto result = std::find(temp, a.end(), b);
      if (result == a.end()) {
        break;
      } else {
        current -= *result;
        *result = c;
        current += c;
        temp = result + 1;
      }
    }
    cout << current << endl;
  }
  return 0;
}
