#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    replace(v.begin(), v.end(), b, c);
    long long sum = 0;
    for (int i = 0; i < v.size(); i++) {
      sum += v[i];
    }
    cout << sum << endl;
  }
  v.clear();
}
