#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  vector<int> nums;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    nums.push_back(x);
  }
  cin >> q;
  while (q--) {
    int b, c, total = 0;
    cin >> b >> c;
    vector<int>::iterator it;
    replace(nums.begin(), nums.end(), b, c);
    cout << accumulate(nums.begin(), nums.end(), 0) << "\n";
  }
}
