#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int q;
long long int segment[400009];
long long int arr[400009];
long long int sum(long long int a, long long int b) {
  a = a + n;
  b = b + n;
  long long int s = 0;
  while (a <= b) {
    if (a % 2 == 1) {
      s = s + segment[a];
      a++;
    }
    if (b % 2 == 0) {
      s = s + segment[b];
      b--;
    }
    a = a / 2;
    b = b / 2;
  }
  return s;
}
void add(long long int k, long long int x) {
  k += n;
  segment[k] += x;
  for (k /= 2; k >= 1; k /= 2) {
    segment[k] = segment[2 * k] + segment[2 * k + 1];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  ;
  cin >> n;
  memset(segment, 0, sizeof(segment));
  memset(arr, 0, sizeof(arr));
  for (int i = 1; i <= n; i++) {
    long long int a;
    cin >> a;
    arr[i] = a;
    add(i, a);
  }
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b;
    int c;
    cin >> b >> c;
    for (int i = 1; i <= n; i++) {
      if (arr[i] == b) {
        add(i, c - b);
        arr[i] = c;
      }
    }
    cout << sum(1, n) << endl;
  }
}
