#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int a[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int pos = lower_bound(a + 1, a + n + 1, x) - a;
    for (int i = pos; i <= n; i++) {
      if (a[i] == x) {
        sum += (y - x);
        a[i] = y;
      } else {
        break;
      }
    }
    cout << sum << '\n';
  }
}
