#include <bits/stdc++.h>
const long long M = 1e9 + 7;
using namespace std;
long long arr[2000005] = {0}, tree[4 * 2000005] = {0};
void buildTree(long long start, long long end, long long index) {
  if (start == end)
    tree[index] = arr[start];
  else {
    long long mid = (start + end) / 2;
    buildTree(start, mid, 2 * index);
    buildTree(mid + 1, end, 2 * index + 1);
    tree[index] = tree[2 * index] + tree[2 * index + 1];
  }
}
void update(long long start, long long end, long long index, long long pos,
            long long val) {
  if (start == end) {
    arr[pos] = val;
    tree[index] = val;
  } else {
    long long mid = (start + end) / 2;
    if (pos >= start && pos <= mid)
      update(start, mid, 2 * index, pos, val);
    else
      update(mid + 1, end, 2 * index + 1, pos, val);
    tree[index] = tree[2 * index] + tree[2 * index + 1];
  }
}
long long query(long long start, long long end, long long index, long long l,
                long long r) {
  if (l <= start && r >= end) return tree[index];
  if (start > r || end < l) return 0;
  long long mid = (start + end) / 2;
  long long q1 = query(start, mid, 2 * index, l, r);
  long long q2 = query(mid + 1, end, 2 * index + 1, l, r);
  return (q1 + q2);
}
void solve() {
  long long n, m;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  buildTree(1, n, 1);
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = 1; j <= n; j++)
      if (arr[j] == x) update(1, n, 1, j, y);
    cout << query(1, n, 1, 1, n) << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; i++) solve();
  return 0;
}
