#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define float long double 

void buildTree(int *arr, int *tree, int s, int e, int idx)
{
  if(s==e)
  {
    tree[idx] = arr[s];
    return;
  }

  if(s>e) return;

  int mid = (s+e)/2;
  buildTree(arr, tree, s, mid, 2*idx);
  buildTree(arr, tree, mid+1, e, 2*idx+1);

  tree[idx] = tree[2*idx] + tree[2*idx+1];
  return;
}

void update(int *tree, int s, int e, int qs, int qe, int idx)
{
  if(s==e)
  {
    if(tree[idx]==qs) tree[idx] = qe;
    return;
  }

  if(s>e) return;

  int mid = (s+e)/2;
  update(tree, s, mid, qs, qe, 2*idx);
  update(tree, mid+1, e, qs, qe, 2*idx+1);

  tree[idx] = tree[2*idx] + tree[2*idx+1];
  return;
}

int32_t main()
{
  IOS;
  int n;
  cin>>n;
  int arr[n];
  for(int i=0; i<n; i++)
  {
    cin>>arr[i];
  }
  int s = 0;
  int e = n-1;
  int idx = 1;
  int tree[4*n+1] = {0};
  buildTree(arr, tree, s, e, idx);
  int q;
  cin>>q;
  while(q--)
  {
    int a,b;
    cin>>a>>b;
    update(tree,s,e,a,b,idx);
    cout<<tree[1]<<endl;
  }
  return 0;
}