#include <bits/stdc++.h>
const long long mod = 1000000007;
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      long long a;
      cin >> a;
      v.push_back(a);
    }
    long long q;
    cin >> q;
    long long b, c;
    for (long long i = 0; i < q; i++) {
      cin >> b >> c;
      replace(v.begin(), v.end(), b, c);
      cout << accumulate(v.begin(), v.end(), 0) << "\n";
      ;
    }
  }
  return 0;
}
