#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned int N;
  cin >> N;
  vector<unsigned int> vect(N);
  for (auto it = vect.begin(); it != vect.end(); it++) cin >> *it;
  unsigned int Q;
  cin >> Q;
  for (auto i = (0); i < (Q); i++) {
    unsigned int B, C;
    cin >> B >> C;
    replace(vect.begin(), vect.end(), B, C);
    cout << accumulate(vect.begin(), vect.end(), 0) << "\n";
  }
}
