#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) cin >> vec[i];
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    replace(vec.begin(), vec.end(), b, c);
    int sum = 0;
    for (auto x : vec) sum += x;
    cout << sum << "\n";
  }
}
