#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; ++i) cin >> a[i];
  long long int k;
  cin >> k;
  for (long long int i = 0; i < k; ++i) {
    long long int l, m;
    cin >> l >> m;
    replace(a.begin(), a.end(), l, m);
    cout << accumulate(a.begin(), a.end(), 0ULL);
    cout << "\n";
  }
  return 0;
}
