#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int num;
  int n;
  cin >> n;
  vector<int> vec;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    vec.push_back(num);
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    replace(vec.begin(), vec.end(), b, c);
    auto sum = accumulate(vec.begin(), vec.end(), 0);
    cout << sum << '\n';
  }
  return 0;
}
