#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Vi = vector<int>;
int main() {
  int n;
  cin >> n;
  Vi a(n);
  int sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  int q;
  cin >> q;
  Vi b(q), c(q), s(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b.at(i) >> c.at(i);
    auto it = find(a.begin(), a.end(), b.at(i));
    while (it != a.end()) {
      *it = c.at(i);
      sum -= b.at(i);
      sum += c.at(i);
      it = find(a.begin(), a.end(), b.at(i));
    }
    cout << sum << endl;
    s.push_back(sum);
  }
  return 0;
}
