#include <bits/stdc++.h>
using namespace std;
long long gcd(long long s, long long t) {
  if (t == 0) return s;
  return gcd(t, s % t);
}
signed main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long w;
  cin >> w;
  long long b[w], c[w];
  for (long long i = 0; i < w; i++) {
    cin >> b[i] >> c[i];
  }
  long long ans = 0;
  for (long long i = 0; i < w; i++) {
    for (long long j = 0; j < n; j++) {
      ans = 0;
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
    }
    for (long long j = 0; j < n; j++) {
      ans += a[j];
    }
    cout << ans << endl;
  }
}
