#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const double PI = 3.14159265358979323846;
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int main() {
  int n;
  cin >> n;
  ll all = 0;
  vector<int> a(n);
  for (ll i = 0; i < (ll)(n); i++) {
    cin >> a[i];
    all += a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (ll i = 0; i < (ll)(q); i++) cin >> b[i] >> c[i];
  vector<ll> s(q, 0);
  for (ll i = 0; i < (ll)(q); i++) {
    for (ll j = 0; j < (ll)(n); j++) {
      if (a[j] == b[i]) {
        int atmp = a[j];
        a[j] = c[i];
        all = all - (atmp - c[i]);
      }
    }
    s[i] = all;
  }
  for (ll i = 0; i < (ll)(q); i++) cout << s[i] << endl;
  return 0;
}
