#include <bits/stdc++.h>
using namespace std;
int n, q;
struct node {
  long long sum;
} tree[100010 << 2];
int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}
void push_up(int rt) {
  tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;
}
void build(int rt, int l, int r) {
  if (l == r) {
    tree[rt].sum = read();
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  push_up(rt);
}
void update(int rt, int b, int c, int l, int r) {
  if (l == r) {
    if (tree[rt].sum == b) tree[rt].sum = c;
    return;
  }
  int mid = (l + r) >> 1;
  update(rt << 1, b, c, l, mid);
  update(rt << 1 | 1, b, c, mid + 1, r);
  push_up(rt);
}
int main() {
  n = read();
  build(1, 1, n);
  q = read();
  for (int i = 1, b, c; i <= q; i++) {
    b = read(), c = read();
    update(1, b, c, 1, n);
    printf("%lld\n", tree[1].sum);
  }
  return 0;
}
