#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (auto &x : v) cin >> x;
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long sum = 0;
    replace((v).begin(), (v).end(), b, c);
    for (int i = 0; i < n; ++i) sum += v[i];
    cout << sum << '\n';
  }
  return 0;
}
