#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    replace(begin(a), end(a), b, c);
    long long s = 0;
    for (long long i = 0; i < n; i++) s += a[i];
    cout << s << endl;
  }
  return 0;
}
