#include <iostream>
#include <bits/stdc++.h>
#define loop(i,N) for(long long int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long>
#define lli long long int
using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(i,v.size()){
        pt<T>(v[i]);
    }
}

/*********************************reused****************************/
int n,m;
vector<lli> a;
map<lli,vector<lli>> maxi;

int main()
{
    cin>>n;
    lli z;
    loop(i,n){
        cin>>z;
        a.push_back(z);
    }
    loop(i,n){
        vector<lli> v(0);
        for(lli j=i;j<n;j++){
            v.push_back(a[j]);
        }
        maxi[i]=v;
    }
    cin >> m;
    lli x,y;
    loop(i,m){
        cin>>x>>y;
        cout<< maxi[0][x-1]<<endl;
        if(i<m-1){
            loop(j,x){
                maxi[0][j] = maxi[0][x-1]+y;
            }
        }

    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define loop(i,N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long>
#define lli long long int
using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(i,v.size()){
        pt<T>(v[i]);
    }
}

/*********************************reused****************************/
int n,m;
const int N=1e5+7;
vector<lli> a;
map<lli,vector<lli>> maxi;
//pair<lli,lli> b[100009];
int main()
{
    cin>>n;
    lli z;
    loop(i,n){
        cin>>z;
        a.push_back(z);
    }
    loop(i,n){
        vector<lli> v(0);
        for(int j=i;j<n;j++){
            v.push_back(a[j]);
        }
        maxi[i]=v;
    }
    cin >> m;
    lli x,y;
    loop(i,m){
        cin>>x>>y;
        cout<< maxi[0][x-1]<<endl;
        if(i<m-1){
            loop(j,x){
                maxi[0][j] = maxi[0][x-1]+y;
            }
        }

    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

const int MAXN= 100105;
int v[MAXN];
long long ST[4*MAXN], L[4*MAXN];

long long query(int node, int lo, int hi, int i, int j){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(i > hi || j < lo)
        return -1;

    if(lo >= i && hi <= j)
        return ST[node];

    int mid = (lo + hi) / 2;

    return max(query(2*node, lo, mid, i, j), query(2*node+1, mid + 1, hi, i, j));
}

void update(int node, int lo, int hi, int i, int j, long long val){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(j < lo || i > hi)
        return;

    if(lo >= i && hi <= j){
        ST[node] = val;
        L[node] = val;
        return;
    }

    int mid = (lo + hi) / 2;
    update(2*node, lo, mid, i, j, val);
    update(2*node+1, mid + 1, hi, i, j , val);

    ST[node] = max(ST[2*node], ST[2*node+1]);

}

void build(int node, int lo, int hi){

    if(lo == hi){
        ST[node] = v[lo];
        return;
    }

    int mid = (lo + hi) / 2;
    build(2*node, lo, mid);
    build(2*node+1, mid + 1, hi);

    ST[node] = max(ST[2*node], ST[2*node + 1]);
}
int main()
{
    int n; cin >> n;

    for(int i = 0 ; i < n; i++)
        cin >> v[i];

    build(1, 0, n-1);

    int q; cin >> q;

    for(int i = 0; i < q; i++){
        long long w, h; cin >> w >> h;

        long long ans = query(1, 0, n - 1, 0, w - 1);

        printf("%I64d\n", ans);
        update(1, 0, n-1, 0, w-1, (long long)ans + h);

    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

const int MAXN= 100105;
int v[MAXN];
long long ST[4*MAXN], L[4*MAXN];

long long query(int node, int lo, int hi, int i, int j){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(i > hi || j < lo)
        return -1;

    if(lo >= i && hi <= j)
        return ST[node];

    int mid = (lo + hi) / 2;

    return max(query(2*node, lo, mid, i, j), query(2*node+1, mid + 1, hi, i, j));
}

void update(int node, int lo, int hi, int i, int j, int val){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(j < lo || i > hi)
        return;

    if(lo >= i && hi <= j){
        ST[node] = val;
        L[node] = val;
        return;
    }

    int mid = (lo + hi) / 2;
    update(2*node, lo, mid, i, j, val);
    update(2*node+1, mid + 1, hi, i, j , val);

    ST[node] = max(ST[2*node], ST[2*node+1]);

}

void build(int node, int lo, int hi){

    if(lo == hi){
        ST[node] = v[lo];
        return;
    }

    int mid = (lo + hi) / 2;
    build(2*node, lo, mid);
    build(2*node+1, mid + 1, hi);

    ST[node] = max(ST[2*node], ST[2*node + 1]);
}
int main()
{
    int n; cin >> n;

    for(int i = 0 ; i < n; i++)
        cin >> v[i];

    build(1, 0, n-1);

    int q; cin >> q;

    for(int i = 0; i < q; i++){
        long long w, h; cin >> w >> h;

        long long ans = query(1, 0, n - 1, 0, w - 1);

        printf("%I64d\n", ans);
        update(1, 0, n-1, 0, w-1, (long long)ans + h);

    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

const int MAXN= 100105;
int v[MAXN];
long long ST[4*MAXN], L[4*MAXN];

long long query(int node, int lo, int hi, int i, int j){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(i > hi || j < lo)
        return -1;

    if(lo >= i && hi <= j)
        return ST[node];

    int mid = (lo + hi) / 2;

    return max(query(2*node, lo, mid, i, j), query(2*node+1, mid + 1, hi, i, j));
}

void update(int node, int lo, int hi, int i, int j, int val){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(j < lo || i > hi)
        return;

    if(lo >= i && hi <= j){
        ST[node] = val;
        L[node] = val;
        return;
    }

    int mid = (lo + hi) / 2;
    update(2*node, lo, mid, i, j, val);
    update(2*node+1, mid + 1, hi, i, j , val);

    ST[node] = max(ST[2*node], ST[2*node+1]);

}

void build(int node, int lo, int hi){

    if(lo == hi){
        ST[node] = v[lo];
        return;
    }

    int mid = (lo + hi) / 2;
    build(2*node, lo, mid);
    build(2*node+1, mid + 1, hi);

    ST[node] = max(ST[2*node], ST[2*node + 1]);
}
int main()
{
    int n; cin >> n;

    for(int i = 0 ; i < n; i++)
        cin >> v[i];

    build(1, 0, n-1);

    int q; cin >> q;

    for(int i = 0; i < q; i++){
        ll w, h; cin >> w >> h;

        long long ans = query(1, 0, n - 1, 0, w - 1);

        printf("%I64d\n", ans);
        update(1, 0, n-1, 0, w-1, (long long)ans + h);

    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

const int MAXN= 100105;
int v[MAXN];
long long ST[4*MAXN], L[4*MAXN];

long long query(int node, int lo, int hi, int i, int j){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(i > hi || j < lo)
        return -1;

    if(lo >= i && hi <= j)
        return ST[node];

    int mid = (lo + hi) / 2;

    return max(query(2*node, lo, mid, i, j), query(2*node+1, mid + 1, hi, i, j));
}

void update(int node, int lo, int hi, int i, int j, int val){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(j < lo || i > hi)
        return;

    if(lo >= i && hi <= j){
        ST[node] = val;
        L[node] = val;
        return;
    }

    int mid = (lo + hi) / 2;
    update(2*node, lo, mid, i, j, val);
    update(2*node+1, mid + 1, hi, i, j , val);

    ST[node] = max(ST[2*node], ST[2*node+1]);

}

void build(int node, int lo, int hi){

    if(lo == hi){
        ST[node] = v[lo];
        return;
    }

    int mid = (lo + hi) / 2;
    build(2*node, lo, mid);
    build(2*node+1, mid + 1, hi);

    ST[node] = max(ST[2*node], ST[2*node + 1]);
}
int main()
{
    int n; cin >> n;

    for(int i = 0 ; i < n; i++)
        cin >> v[i];

    build(1, 0, n-1);

    int q; cin >> q;

    for(int i = 0; i < q; i++){
        int w, h; cin >> w >> h;

        long long ans = query(1, 0, n - 1, 0, w - 1);

        printf("%I64d\n", ans);
        update(1, 0, n-1, 0, w-1, ans + h);

    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

const int MAXN= 100105;
int v[MAXN];
long long ST[4*MAXN], L[4*MAXN];

long long query(int node, int lo, int hi, int i, int j){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(i > hi || j < lo)
        return -(1 << 25);

    if(lo >= i && hi <= j)
        return ST[node];

    int mid = (lo + hi) / 2;

    return max(query(2*node, lo, mid, i, j), query(2*node+1, mid + 1, hi, i, j));
}

void update(int node, int lo, int hi, int i, int j, int val){

    if(L[node]){

        ST[node] = L[node];
        L[2*node] = L[node];
        L[2*node+1] = L[node];

        L[node] = 0;
    }

    if(j < lo || i > hi)
        return;

    if(lo >= i && hi <= j){
        ST[node] = val;
        L[node] = val;
        return;
    }

    int mid = (lo + hi) / 2;
    update(2*node, lo, mid, i, j, val);
    update(2*node+1, mid + 1, hi, i, j , val);

    ST[node] = max(ST[2*node], ST[2*node+1]);

}

void build(int node, int lo, int hi){

    if(lo == hi){
        ST[node] = v[lo];
        return;
    }

    int mid = (lo + hi) / 2;
    build(2*node, lo, mid);
    build(2*node+1, mid + 1, hi);

    ST[node] = max(ST[2*node], ST[2*node + 1]);
}
int main()
{
    int n; cin >> n;

    for(int i = 0 ; i < n; i++)
        cin >> v[i];

    build(1, 0, n-1);

    int q; cin >> q;

    for(int i = 0; i < q; i++){
        int w, h; cin >> w >> h;

        long long ans = query(1, 0, n - 1, 0, w - 1);

        printf("%I64d\n", ans);
        update(1, 0, n-1, 0, w-1, ans + h);

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n, a[100009], m, x, y;
int main() {
    cin>>n;

    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    cin>>m;
    for(int i=1;i<=m;i++) {
        cin>>x>>y;
        cout << max(a[1],a[x])<<'\n';
        a[1]=max(a[1],a[x])+y;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    cout<<"Hello";
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define N 100005
#define md ((l+r)/2)
using namespace std;
typedef long long llong;

const llong oo = LONG_LONG_MAX;

int n, m, a[N], d[4*N];
llong f[4*N];

void build(int k, int l, int r) {
    if (l == r) { f[k]=llong(a[l]);  return; }
    build(2*k,l,md);    build(2*k+1,md+1,r);
    f[k]=max(f[2*k],f[2*k+1]);
}

void lazy(int k) {
    if (2*k+1 <= 4*N) { f[2*k]=f[2*k+1]=f[k]; d[2*k]=d[2*k+1]=1; }
    d[k]=0;
}

llong get(int k, int l, int r, int u) {
    if (l > u) return 0LL; else if (d[k]) lazy(k);
    if (r <= u) return f[k]; else return max(get(2*k,l,md,u), get(2*k+1,md+1,r,u));
}

void modify(int k, int l, int r, int u, llong v) {
    if (l > u) return; else if (d[k]) lazy(k);
    if (r <= u) {
        d[k]=1;  f[k]=v;  return;
    } else { modify(2*k,l,md,u,v); modify(2*k+1,md+1,r,u,v); }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
    //freopen("a.txt", "r", stdin);
    //freopen("b.txt", "w", stdout);

    cin>>n; rep(i,1,n) cin>>a[i];
    build(1,1,n);

    cin>>m;  int u;     llong v, ans;
    rep(i,1,m) {
        cin>>u>>v;
        ans=get(1,1,n,u);
        cout<<ans<<endl;
        modify(1,1,n,u,v+ans);
    }
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define N 100005
#define md ((l+r)/2)
using namespace std;
typedef long long llong;

const llong oo = LONG_LONG_MAX;

int n, m, a[N], d[4*N];
llong f[4*N];

void build(int k, int l, int r) {
    if (l == r) { f[k]=llong(a[l]);  return; }
    build(2*k,l,md);    build(2*k+1,md+1,r);
    f[k]=max(f[2*k],f[2*k+1]);
}

void lazy(int k) {
    if (2*k+1 <= 4*N) { f[2*k]=f[2*k+1]=f[k]; d[2*k]=d[2*k+1]=1; }
    d[k]=0;
}

llong get(int k, int l, int r, int u) {
    if (l > u) return 0LL; else if (d[k]) lazy(k);
    if (r <= u) return f[k]; else return max(get(2*k,l,md,u), get(2*k+1,md+1,r,u));
}

void modify(int k, int l, int r, int u, llong v) {
    if (l > u) return; else if (d[k]) lazy(k);
    if (r <= u) {
        d[k]=1;  f[k]=v;  return;
    } else { modify(2*k,l,md,u,v); modify(2*k+1,md+1,r,u,v); }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);

    cin>>n; rep(i,1,n) cin>>a[i];
    build(1,1,n);

    cin>>m;  int u;     llong v, ans;
    rep(i,1,m) {
        cin>>u>>v;
        ans=get(1,1,n,u);
        cout<<ans<<endl;
        modify(1,1,n,u,v+ans);
    }
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define N 100005
#define md ((l+r)/2)
using namespace std;
typedef long long llong;

const llong oo = LONG_LONG_MAX;

int n, m, a[N], d[4*N];
llong f[4*N];

void build(int k, int l, int r) {
    if (l == r) { f[k]=llong(a[l]);  return; }
    build(2*k,l,md);    build(2*k+1,md+1,r);
    f[k]=max(f[2*k],f[2*k+1]);
}

void lazy(int k) {
    if (2*k+1 <= 4*N) { f[2*k]=f[2*k+1]=f[k]; d[2*k]=d[2*k+1]=1; }
    d[k]=0;
}

llong get(int k, int l, int r, int u) {
    if (l > u) return -oo; else if (d[k]) lazy(k);
    if (r <= u) return f[k]; else return max(get(2*k,l,md,u), get(2*k+1,md+1,r,u));
}

void modify(int k, int l, int r, int u, llong v) {
    if (l > u) return; else if (d[k]) lazy(k);
    if (r <= u) {
        d[k]=1;  f[k]=v;  return;
    } else { modify(2*k,l,md,u,v); modify(2*k+1,md+1,r,u,v); }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
    //freopen("a.txt", "r", stdin);
    //freopen("b.txt", "w", stdout);

    cin>>n; rep(i,1,n) cin>>a[i];
    build(1,1,n);

    cin>>m;  int u;     llong v, ans;
    rep(i,1,m) {
        cin>>u>>v;
        ans=get(1,1,n,u);
        cout<<ans<<endl;
        modify(1,1,n,u,v+ans);
    }
}


#include <bits/stdc++.h>
using namespace std;

#define fl(i, start, end) for(int i = start; i < end; i++)
#define flr(i, start, end) for(int i = start; i >= end; i--)
#define w(x) while(x--)
#define int long long
#define maxLimit 1000006
#define vi vector<int>
#define pii pair<int, int>
#define intin(i) int i; cin >> i
#define charin(i) char i; cin >> i
#define floatin(i) float i; cin >> i
#define doublein(i) double i; cin >> i
#define stringin(i) string i; cin >> i

void cpSetup() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("cf.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int32_t main() {
	cpSetup();

	intin(n);
	int arr[n];
	fl(i, 0, n)
		cin >> arr[i];

	intin(b);
	w(b) {
		int w, h;
		cin >> w >> h;
		cout << arr[w - 1] << endl;
		arr[w - 1] += h;
		flr(idx, w - 1, 0) {
			arr[idx] = arr[w - 1];
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fl(i, start, end) for(int i = start; i < end; i++)
#define flr(i, start, end) for(int i = start; i >= end; i--)
#define w(x) while(x--)
#define int long long
#define maxLimit 1000006
#define vi vector<int>
#define pii pair<int, int>
#define intin(i) int i; cin >> i
#define charin(i) char i; cin >> i
#define floatin(i) float i; cin >> i
#define doublein(i) double i; cin >> i
#define stringin(i) string i; cin >> i

void cpSetup() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("cf.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int32_t main() {
	cpSetup();

	intin(n);
	int arr[n];
	fl(i, 0, n)
		cin >> arr[i];

	intin(b);
	int last = 0;
	int h1 = 0;
	w(b) {
		int w2, h2;
		cin >> w2 >> h2;
		last = max(last + h1, arr[w2 - 1]);
		h1 = h2;
		cout << last << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fl(i, start, end) for(int i = start; i < end; i++)
#define flr(i, start, end) for(int i = start; i >= end; i--)
#define w(x) while(x--)
#define int long long
#define maxLimit 1000006
#define vi vector<int>
#define pii pair<int, int>
#define intin(i) int i; cin >> i
#define charin(i) char i; cin >> i
#define floatin(i) float i; cin >> i
#define doublein(i) double i; cin >> i
#define stringin(i) string i; cin >> i

void cpSetup() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("cf.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int32_t main() {
	cpSetup();

	intin(n);
	int arr[n];
	fl(i, 0, n)
		cin >> arr[i];

	intin(b);
	w(b) {
		int w, h;
		cin >> w >> h;
		cout << arr[w - 1] << endl;
		arr[w - 1] += h;
		flr(idx, w - 1, 0) {
			arr[idx] = arr[w - 1];
		}
		fl(idx, w, n) {
			if(arr[idx] > arr[w - 1])
				break;
			arr[idx] = arr[w - 1];
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000007
#define ll long long
const int N = 100005;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
    int n, m, a[N];
    ll MaxHeight;
    pair<int, int>x[N];
    scanf("%d", &n);
    for(int i=0;i<n;i++)
        scanf("%d", a+i);
     scanf("%d%d%d", &m, &x[0].first, &x[0].second);
    MaxHeight = a[x[0].first-1] + x[0].second;
    printf("%d\n", a[x[0].first-1]);
    for(int i=1;i<m;i++){
        scanf("%d%d", &x[i].first, &x[i].second);
        if(MaxHeight >= a[x[i].first-1]){
            printf("%d\n", MaxHeight);
            MaxHeight += x[i].second;
        } else {
            printf("%d\n", a[x[i].first-1]);
            MaxHeight = a[x[i].first-1] + x[i].second;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000007
#define ll long long
const int N = 100005;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
    int n, m, a[N], MaxHeight;
    pair<int, int>x[N];
    scanf("%d", &n);
    for(int i=0;i<n;i++)
        scanf("%d", a+i);
     scanf("%d%d%d", &m, &x[0].first, &x[0].second);
    MaxHeight = a[x[0].first-1] + x[0].second;
    printf("%d\n", a[x[0].first-1]);
    for(int i=1;i<m;i++){
        scanf("%d%d", &x[i].first, &x[i].second);
        if(MaxHeight >= a[x[i].first-1]){
            printf("%d\n", MaxHeight);
            MaxHeight += x[i].second;
        } else {
            printf("%d\n", a[x[i].first-1]);
            MaxHeight = a[x[i].first-1] + x[i].second;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000007
const int N = 100005;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
    int n, m, a[N];
    ll MaxHeight;
    pair<int, int>x[N];
    scanf("%d", &n);
    for(int i=0;i<n;i++)
        scanf("%d", a+i);
     scanf("%d%d%d", &m, &x[0].first, &x[0].second);
    MaxHeight = a[x[0].first-1] + x[0].second;
    cout << a[x[0].first-1] << endl;
    for(int i=1;i<m;i++){
        scanf("%d%d", &x[i].first, &x[i].second);
        if(MaxHeight >= a[x[i].first-1]){
            cout << MaxHeight << endl;
            MaxHeight += x[i].second;
        } else {
            cout << a[x[i].first-1] << endl;
            MaxHeight = a[x[i].first-1] + x[i].second;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000007
#define ll long long
const int N = 100005;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
    int n, m, a[N];
    ll MaxHeight;
    pair<int, int>x[N];
    scanf("%d", &n);
    for(int i=0;i<n;i++)
        scanf("%d", a+i);
     scanf("%d%d%d", &m, &x[0].first, &x[0].second);
    MaxHeight = a[x[0].first-1] + x[0].second;
    cout << a[x[0].first-1] << endl;
    for(int i=1;i<m;i++){
        scanf("%d%d", &x[i].first, &x[i].second);
        if(MaxHeight >= a[x[i].first-1]){
            cout << MaxHeight << endl;
            MaxHeight += x[i].second;
        } else {
            cout << a[x[i].first-1] << endl;
            MaxHeight = a[x[i].first-1] + x[i].second;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000007
#define ll long long
const int N = 100005;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
    int n, m, a[N];
    ll MaxHeight;
    pair<int, int>x[N];
    scanf("%d", &n);
    for(int i=0;i<n;i++)
        scanf("%d", a+i);
     scanf("%d%d%d", &m, &x[0].first, &x[0].second);
    MaxHeight = a[x[0].first-1] + x[0].second;
    printf("%d\n", a[x[0].first-1]);
    for(int i=1;i<m;i++){
        scanf("%d%d", &x[i].first, &x[i].second);
        if(MaxHeight >= a[x[i].first-1]){
            printf("%I64d\n", MaxHeight);
            MaxHeight += x[i].second;
        } else {
            printf("%d\n", a[x[i].first-1]);
            MaxHeight = a[x[i].first-1] + x[i].second;
        }
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
int A[100005]={};
int num[100005]={};
int main()
{
    int a;
    while(cin>>a){
        for(int i=1;i<=a;i++){
            cin>>A[i];
        }
        int now=0;
        int b;
        cin>>b;
        for(int i=0;i<b;i++){
            int x,y;
            cin>>x>>y;
            if(x>now){
                now=x;
            }
            cout<<A[now]<<endl;
            A[x]+=y;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
LL A[100005]={};
int main()
{
    int a;
    while(cin>>a){
        for(int i=1;i<=a;i++){
            cin>>A[i];
        }
        int now=0;
        int b;
        cin>>b;
        for(int i=0;i<b;i++){
            int x,y;
            cin>>x>>y;
            A[now]=max(A[now],A[x]);
            A[x]=max(A[x],A[now]);
            if(x>now){
                now=x;
            }
            cout<<A[now]<<endl;
            A[now]+=y;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
int A[100005]={};
int B[100005]={};
int main()
{
    int a;
    while(cin>>a){
            LL ans=1;
            map<int,int>num;
        for(int i=0;i<a;i++){
            cin>>A[i];
    num[A[i]]++;
        }
        for(int i=0;i<a;i++){
            cin>>B[i];
            num[B[i]]++;
        }
        int b;
        cin>>b;
        int cnt=0;
        for(int i=0;i<a;i++){
            if(A[i]==B[i])
                cnt++;
        }
        for(map<int,int>::iterator i=num.begin();i!=num.end();i++){
           int k= i->second;
           for(int j=2;j<=k;j++){
            ans*=j;
                       if(cnt&&ans%2==0){
            cnt--;
            ans/=2;
           }
           }
ans%=b;
        }
cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
int A[100005]={};
int num[100005]={};
int main()
{
    int a;
    while(cin>>a){
        for(int i=1;i<=a;i++){
            cin>>A[i];
        }
        int now=0;
        int b;
        cin>>b;
        for(int i=0;i<b;i++){
            int x,y;
            cin>>x>>y;
            A[now]=max(A[now],A[x]);
            A[x]=max(A[x],A[now]);
            if(x>now){
                now=x;
            }
            cout<<A[now]<<endl;
            A[now]+=y;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
int A[100005]={};
int num[100005]={};
int main()
{
    int a;
    while(cin>>a){
        for(int i=1;i<=a;i++){
            cin>>A[i];
        }
        int now=0;
        int b;
        cin>>b;
        for(int i=0;i<b;i++){
            int x,y;
            cin>>x>>y;
            if(x>now){
                now=x;
            }
            cout<<A[now]<<endl;
            A[now]+=y;
        }

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define vlong long long
#define xx first
#define yy second
#define MAXN 100005

int n, m;
vlong tr[4 * MAXN], lzy[4 * MAXN];

void update(int nm, int st, int ed, int i, int j, vlong v) {
    if(st == i && j == ed) {
        lzy[nm] = v;
        tr[nm] = v;
        return;
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        update(lt, st, md, i, j, v);
    }
    else if(i > md) {
        update(rt, md + 1, ed, i, j, v);
    }
    else {
        update(lt, st, md, i, md, v);
        update(rt, md + 1, ed, md + 1, j, v);
    }

    tr[nm] = max(tr[lt], tr[rt]);
}

vlong query(int nm, int st, int ed, int i, int j) {
    if(st == i && j == ed) {
        return tr[nm];
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        return query(lt, st, md, i, j);
    }
    else if(i > md) {
        return query(rt, md + 1, ed, i, j);
    }
    else{
        return max(query(lt, st, ed, i, md), query(rt, md + 1, ed, md + 1, j));
    }
}

int main() {
    cin >> n;

    for(int i = 1; i <= n; i++) {
        vlong x;
        scanf("%lld", &x);

        update(1, 1, n, i, i, x);
    }

    cin >> m;

    for(int i = 0; i < m; i++) {
        int r;
        vlong ad;
        scanf("%d %lld", &r, &ad);

        vlong res = query(1, 1, n, 1, r);

        printf("%lld\n", res);

        update(1, 1, n, 1, r, res + ad);
    }
}


#include <bits/stdc++.h>

using namespace std;

#define vlong long long
#define xx first
#define yy second
#define MAXN 100005

int n, m;
vlong tr[5 * MAXN], lzy[5 * MAXN];

void update(int nm, int st, int ed, int i, int j, vlong v) {
    if(st == ed) {
        lzy[nm] = v;
        tr[nm] = v;
        return;
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        update(lt, st, md, i, j, v);
    }
    else if(i > md) {
        update(rt, md + 1, ed, i, j, v);
    }
    else {
        update(lt, st, md, i, md, v);
        update(rt, md + 1, ed, md + 1, j, v);
    }

    tr[nm] = max(tr[lt], tr[rt]);
}

vlong query(int nm, int st, int ed, int i, int j) {
    if(st == ed) {
        return tr[nm];
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        return query(lt, st, md, i, j);
    }
    else if(i > md) {
        return query(rt, md + 1, ed, i, j);
    }
    else{
        return max(query(lt, st, ed, i, md), query(rt, md + 1, ed, md + 1, j));
    }
}

int main() {
    cin >> n;

    for(int i = 1; i <= n; i++) {
        vlong x;
        scanf("%lld", &x);

        update(1, 1, n, i, i, x);
    }

    cin >> m;

    for(int i = 0; i < m; i++) {
        int r;
        vlong ad;
        scanf("%d %lld", &r, &ad);

        vlong res = query(1, 1, n, 1, r);

        printf("%lld\n", res);

        update(1, 1, n, 1, r, res + ad);
    }
}


#include <bits/stdc++.h>

using namespace std;

#define vlong long long
#define xx first
#define yy second
#define MAXN 100005

int n, m;
vlong tr[5 * MAXN], lzy[5 * MAXN];

void update(int nm, int st, int ed, int i, int j, vlong v) {
    if(st == i && j == ed) {
        lzy[nm] = v;
        tr[nm] = v;
        return;
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        update(lt, st, md, i, j, v);
    }
    else if(i > md) {
        update(rt, md + 1, ed, i, j, v);
    }
    else {
        update(lt, st, md, i, md, v);
        update(rt, md + 1, ed, md + 1, j, v);
    }

    tr[nm] = max(tr[lt], tr[rt]);
}

vlong query(int nm, int st, int ed, int i, int j) {
    if(st == i && j == ed) {
        return tr[nm];
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        return query(lt, st, md, i, j);
    }
    else if(i > md) {
        return query(rt, md + 1, ed, i, j);
    }
    else{
        return max(query(lt, st, ed, i, md), query(rt, md + 1, ed, md + 1, j));
    }
}

int main() {
    cin >> n;

    for(int i = 1; i <= n; i++) {
        vlong x;
        scanf("%lld", &x);

        update(1, 1, n, i, i, x);
    }

    cin >> m;

    for(int i = 0; i < m; i++) {
        int r;
        vlong ad;
        scanf("%d %lld", &r, &ad);

        vlong res = query(1, 1, n, 1, r);

        printf("%lld\n", res);

        update(1, 1, n, 1, r, res + ad);
    }
}


#include <bits/stdc++.h>

using namespace std;

#define vlong long long
#define xx first
#define yy second
#define MAXN 100005

int n, m;
vlong tr[4 * MAXN], lzy[4 * MAXN];

void update(int nm, int st, int ed, int i, int j, vlong v) {
    if(st == ed) {
        lzy[nm] = v;
        tr[nm] = v;
        return;
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        update(lt, st, md, i, j, v);
    }
    else if(i > md) {
        update(rt, md + 1, ed, i, j, v);
    }
    else {
        update(lt, st, md, i, md, v);
        update(rt, md + 1, ed, md + 1, j, v);
    }

    tr[nm] = max(tr[lt], tr[rt]);
}

vlong query(int nm, int st, int ed, int i, int j) {
    if(st == ed) {
        return tr[nm];
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != 0) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = 0;
    }

    if(j <= md) {
        return query(lt, st, md, i, j);
    }
    else if(i > md) {
        return query(rt, md + 1, ed, i, j);
    }
    else{
        return max(query(lt, st, ed, i, md), query(rt, md + 1, ed, md + 1, j));
    }
}

int main() {
    cin >> n;

    for(int i = 1; i <= n; i++) {
        vlong x;
        scanf("%lld", &x);

        update(1, 1, n, i, i, x);
    }

    cin >> m;

    for(int i = 0; i < m; i++) {
        int r;
        vlong ad;
        scanf("%d %lld", &r, &ad);

        vlong res = query(1, 1, n, 1, r);

        printf("%lld\n", res);

        update(1, 1, n, 1, r, res + ad);
    }
}


#include <bits/stdc++.h>

using namespace std;

#define vlong long long
#define xx first
#define yy second
#define MAXN 100005

int n, m;
vlong tr[4 * MAXN], lzy[4 * MAXN];

void update(int nm, int st, int ed, int i, int j, vlong v) {
    if(st == ed) {
        tr[nm] = v;
        return;
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != -1) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = -1;
    }

    if(j <= md) {
        update(lt, st, md, i, j, v);
    }
    else if(i > md) {
        update(rt, md + 1, ed, i, j, v);
    }
    else {
        update(lt, st, md, i, md, v);
        update(rt, md + 1, ed, md + 1, j, v);
    }

    tr[nm] = max(tr[lt], tr[rt]);
}

long long query(int nm, int st, int ed, int i, int j) {
    if(st == ed) {
        return tr[nm];
    }

    int md = (st + ed) / 2;
    int lt = nm * 2;
    int rt = lt + 1;

    if(lzy[nm] != -1) {
        update(lt, st, md, st, md, lzy[nm]);
        update(rt, md + 1, ed, md + 1, ed, lzy[nm]);
        lzy[nm] = -1;
    }

    if(j <= md) {
        return query(lt, st, md, i, j);
    }
    else if(i > md) {
        return query(rt, md + 1, ed, i, j);
    }
    else{
        return max(query(lt, st, ed, i, md), query(rt, md + 1, ed, md + 1, j));
    }
}

int main() {
    cin >> n;

    memset(lzy, -1, sizeof lzy);

    for(int i = 1; i <= n; i++) {
        vlong x;
        scanf("%lld", &x);

        update(1, 1, n, i, i, x);
    }

    cin >> m;

    for(int i = 0; i < m; i++) {
        int r;
        vlong ad;
        scanf("%d %lld", &r, &ad);

        vlong res = query(1, 1, n, 1, r);

        printf("%lld\n", res);

        update(1, 1, n, 1, r, res + ad);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int MAXN=100001;
vector<int> staircase(MAXN);

int main(){
	int n;
	cin >> n;

	for(int i=0;i<n;i++){
		cin >> staircase[i];
	}
	vector<int> sum_staircase;
	int tempMin=0;
	for(int i=0;i<n;i++){
		tempMin=max(tempMin,staircase[i]);
		sum_staircase.push_back(tempMin);
	}

	int m;
	cin >> m;
	while(m--){
		int w,h;
		cin >> w >> h;
		cout << sum_staircase[w-1] << "\n";
		for(int i=0;i<=w-1;i++){
			sum_staircase[i]=sum_staircase[w-1]+h;
		}
	}

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<int> staircase(n);
	for(int i=0;i<n;i++){
		cin >> staircase[i];
	}

	int m;
	cin >> m;
	int L=0,w1=0,h1=0;

	while(m--){
		int w2,h2;
		cin >> w2 >> h2;
		cout << max(L+h1,staircase[w2-1]) << "\n";
		L=max(L+h1,staircase[w2-1]);
		w1=w2;
		h1=h2;
	}

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<ll> staircase(n);
	for(int i=0;i<n;i++){
		cin >> staircase[i];
	}

	ll m;
	cin >> m;
	ll L=0,w1=0,h1=0;

	while(m--){
		ll w2,h2;
		cin >> w2 >> h2;
		cout << max(L+h1,staircase[w2-1]) << "\n";
		L=max(L+h1,staircase[w2-1]);
		w1=w2;
		h1=h2;
	}

}


 #include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<algorithm>
#include<queue>
#include <cstring>
using namespace std ;
#define khaledOsama ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define re return
#define MOD 1000000007
#define lp(i,w,e) for(int i=w;i<e;i++)
#define pb push_back
#define clr(v, d) memset(v, d, sizeof(v))
#define mp make_pair
#define all(x) x.begin(),x.end()
const long long  OO =(long long)1e15+1;
const int MAX=1e5+1;
typedef long long ll;
typedef unsigned long long ull;
typedef  pair<int,int> pii;
typedef  pair<ll,ll> pll;
typedef long double ld;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string>vs;
typedef  vector<pii> vpii;
typedef  vector<pll > vpll;
typedef  bitset <16> MASK;
int main(){
khaledOsama;
int n,arr[100001]={},maxx[100001]={},m,x,y;
cin>>n;
lp(i,1,n+1){cin>>arr[i];maxx[i]=max(arr[i],arr[i-1]);}
cin>>m;
lp(i,0,m){
cin>>x>>y;
cout<<maxx[x]<<endl;
lp(i,1,x+1){
maxx[i]=maxx[x]+y;

}

}
}


 #include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<algorithm>
#include<queue>
#include <cstring>
using namespace std ;
#define khaledOsama ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define re return
#define MOD 1000000007
#define lp(i,w,e) for(int i=w;i<e;i++)
#define pb push_back
#define clr(v, d) memset(v, d, sizeof(v))
#define mp make_pair
#define all(x) x.begin(),x.end()
const long long  OO =(long long)1e15+1;
const int MAX=1e5+1;
typedef long long ll;
typedef unsigned long long ull;
typedef  pair<int,int> pii;
typedef  pair<ll,ll> pll;
typedef long double ld;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string>vs;
typedef  vector<pii> vpii;
typedef  vector<pll > vpll;
typedef  bitset <16> MASK;
int main(){
khaledOsama;
int n,arr[100001]={},maxx[100001]={},m,x,y,w=0;
cin>>n;
lp(i,1,n+1){cin>>arr[i];maxx[i]=max(arr[i],arr[i-1]);}
cin>>m;
lp(i,0,m){
cin>>x>>y;
cout<<maxx[x]<<endl;
w=0;
lp(j,1,n+1){
    w++;
    if(j<=x)arr[j]=maxx[x]+y;

    maxx[j]=arr[j]=max(arr[j],arr[j-1]);

}
}
}


 #include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<algorithm>
#include<queue>
#include <cstring>
using namespace std ;
#define khaledOsama ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define re return
#define MOD 1000000007
#define lp(i,w,e) for(int i=w;i<e;i++)
#define pb push_back
#define clr(v, d) memset(v, d, sizeof(v))
#define mp make_pair
#define all(x) x.begin(),x.end()
const long long  OO =(long long)1e15+1;
const int MAX=1e5+1;
typedef long long ll;
typedef unsigned long long ull;
typedef  pair<int,int> pii;
typedef  pair<ll,ll> pll;
typedef long double ld;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string>vs;
typedef  vector<pii> vpii;
typedef  vector<pll > vpll;
typedef  bitset <16> MASK;
int main(){
khaledOsama;
int n,arr[100001]={},m,x,y,l=1,maxx=0;
cin>>n;
lp(i,1,n+1){cin>>arr[i];}
cin>>m;
lp(i,0,m){
cin>>x>>y;
lp(j,l,x+1){
    maxx=max(maxx,arr[j]); l++;
}
cout<<maxx<<endl;
maxx+=y;
}
}


 #include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<algorithm>
#include<queue>
#include <cstring>
using namespace std ;
#define khaledOsama ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define re return
#define MOD 1000000007
#define lp(i,w,e) for(int i=w;i<e;i++)
#define pb push_back
#define clr(v, d) memset(v, d, sizeof(v))
#define mp make_pair
#define all(x) x.begin(),x.end()
const long long  OO =(long long)1e15+1;
const int MAX=1e5+1;
typedef long long ll;
typedef unsigned long long ull;
typedef  pair<int,int> pii;
typedef  pair<ll,ll> pll;
typedef long double ld;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string>vs;
typedef  vector<pii> vpii;
typedef  vector<pll > vpll;
typedef  bitset <16> MASK;
int main(){
khaledOsama;
int n,arr[100001]={},m,x,y,maxx=0;
cin>>n;
lp(i,1,n+1){cin>>arr[i];}
cin>>m;
lp(i,0,m){
cin>>x>>y;
lp(j,1,x+1){
    maxx=max(maxx,arr[j]);
}
cout<<maxx<<endl;
maxx+=y;
}
}


 #include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<algorithm>
#include<queue>
#include <cstring>
using namespace std ;
#define khaledOsama ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define re return
#define MOD 1000000007
#define lp(i,w,e) for(int i=w;i<e;i++)
#define pb push_back
#define clr(v, d) memset(v, d, sizeof(v))
#define mp make_pair
#define all(x) x.begin(),x.end()
const long long  OO =(long long)1e15+1;
const int MAX=1e5+1;
typedef long long ll;
typedef unsigned long long ull;
typedef  pair<int,int> pii;
typedef  pair<ll,ll> pll;
typedef long double ld;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string>vs;
typedef  vector<pii> vpii;
typedef  vector<pll > vpll;
typedef  bitset <16> MASK;
int main(){
khaledOsama;
ll n,arr[100001]={},m,x,y,l=1,maxx=0;
cin>>n;
lp(i,1,n+1){cin>>arr[i];}
cin>>m;
lp(i,0,m){
cin>>x>>y;
lp(j,l,x+1){
    maxx=max(maxx,arr[j]); l++;
}
cout<<maxx<<endl;
maxx+=y;
}
}


#include<cstdio>
main()
{
    int n;
    scanf("%d",&n);
	long long high[n];
	for(int i=0;i<n;i++) scanf("I64d",&high[i]);
	int nbox;
	scanf("%d",&nbox);
	for(int i=0;i<nbox;i++)
    {
        int w,h;
        scanf("%d %d",&w,&h);
        printf("%I64d\n",high[w-1]);
        long long temp=high[w-1]+h;
        for(int j=w-1;j>=0;j--) high[j]=temp;
    }
}


#include<cstdio>
main()
{
    int n;
    scanf("%d",&n);
	long long high[n];
	for(int i=0;i<n;i++) scanf("%I64d",&high[i]);
	int nbox;
	scanf("%d",&nbox);
	while(nbox--)
    {
        int w,h;
        scanf("%d %d",&w,&h);
        printf("%I64d\n",high[w-1]);
        long long temp=high[w-1]+h;
        for(int j=0;j<n;j++)
        {
            if(high[j]<temp) high[j]=temp;
            else break;
        }
    }
}


#include<cstdio>
main()
{
    int n;
    scanf("%d",&n);
	long long high[n];
	for(int i=0;i<n;i++) scanf("%I64d",&high[i]);
	int nbox;
	scanf("%d",&nbox);
	for(int i=0;i<nbox;i++)
    {
        int w,h;
        scanf("%d %d",&w,&h);
        printf("%I64d\n",high[w-1]);
        long long temp=high[w-1]+h;
        for(int j=w-1;j>=0;j--) high[j]=temp;
    }
}


#include<cstdio>
main()
{
    int n;
    scanf("%d",&n);
	long long high[n];
	for(int i=0;i<n;i++) scanf("%I64d",&high[i]);
	int nbox;
	scanf("%d",&nbox);
	for(int i=0;i<nbox;i++)
    {
        int w,h;
        scanf("%d %d",&w,&h);
        printf("%I64d\n",high[w-1]);
        long long temp=high[w-1]+h;
        for(int j=0;j<n;j++)
        {
            if(high[j]<temp) high[j]=temp;
            else break;
        }
    }
}


#include<cstdio>
main()
{
    int n;
    scanf("%d",&n);
	long long high[n];
	for(int i=0;i<n;i++) scanf("%I64d",&high[i]);
	int nbox;
	scanf("%d",&nbox);
	while(nbox--)
    {
        int w,h;
        scanf("%d %d",&w,&h);
        if(high[0]<high[w-1]) high[0]=high[w-1];
        printf("%I64d\n",high[0]);
        high[0]+=h;
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   LL;
typedef unsigned long long          ULL;
typedef vector<int>                 vi;
typedef vector<vi>                  vvi;
typedef pair<int,int>               pii;
typedef pair<LL,LL>                 pll;
typedef complex<double>             point;

#define X                           real()
#define Y                           imag()
#define angle(p)                    atan2(p.Y,p.X)
#define vec(a,b)                    (b-a)
#define dot_p(v1,v2)                (conj(v1)*v2).X
#define cross_p(v1,v2)              (conj(v1)*v2).Y
#define length(p)                   hypot(p.X,p.Y)
#define lengthSqr(p)                dot_p(p,p)
#define rotateO(p,theta)            (p*exp(point(0,theta)))
#define rotateA(p,theta,about)      rotateO(vac(about,p), theta) + about
#define reflectO(p,m)               conj(p/m)*m
#define reflectA(p,p0,pm)           conj(vec(p0,p)/vec(p0,pm))*vec(p0,pm) + p0
#define scf                         scanf
#define prf                         printf
#define F_IO                        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(c)                      c.begin(),c.end()
#define sz(c)                       ((int)((c).size()))
#define pb                          push_back
#define eb                          emplace_back
#define popb                        pop_back
#define mp                          make_pair
#define xf                          first
#define ys                          second
#define lp(i,s,e)                   for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)                  for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)                for(const auto &var : c)
#define mems(c,val)                 memset(c,val,sizeof(c))
#define mod                         1000000007
#define OOi                         (~(1<<31))
#define OOl                         (~(1LL<<63))
#define PI                          (3.141592654)
#define EPS                         (1e-9)
//_________________________________________________________________________________.
const int N=1e5+9;
LL x[N];

int main(){
	int n;
	scf("%d", &n);
	lp(i,1,n+1) scf("%I64d", x+i);
	int q;
	scf("%d", &q);
	while(q--){
		int w, h;
		scf("%d %d", &w, &h);

		x[1]=x[w]=(x[1]>x[w]?x[1]:x[w]);
		prf("%I64d\n", x[1]);
		x[1]+=h, x[w]+=(1!=w?h:0);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   LL;
typedef unsigned long long          ULL;
typedef vector<int>                 vi;
typedef vector<vi>                  vvi;
typedef pair<int,int>               pii;
typedef pair<LL,LL>                 pll;
typedef complex<double>             point;

#define X                           real()
#define Y                           imag()
#define angle(p)                    atan2(p.Y,p.X)
#define vec(a,b)                    (b-a)
#define dot_p(v1,v2)                (conj(v1)*v2).X
#define cross_p(v1,v2)              (conj(v1)*v2).Y
#define length(p)                   hypot(p.X,p.Y)
#define lengthSqr(p)                dot_p(p,p)
#define rotateO(p,theta)            (p*exp(point(0,theta)))
#define rotateA(p,theta,about)      rotateO(vac(about,p), theta) + about
#define reflectO(p,m)               conj(p/m)*m
#define reflectA(p,p0,pm)           conj(vec(p0,p)/vec(p0,pm))*vec(p0,pm) + p0
#define scf                         scanf
#define prf                         printf
#define F_IO                        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(c)                      c.begin(),c.end()
#define sz(c)                       ((int)((c).size()))
#define pb                          push_back
#define eb                          emplace_back
#define popb                        pop_back
#define mp                          make_pair
#define xf                          first
#define ys                          second
#define lp(i,s,e)                   for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)                  for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)                for(const auto &var : c)
#define mems(c,val)                 memset(c,val,sizeof(c))
#define mod                         1000000007
#define OOi                         (~(1<<31))
#define OOl                         (~(1LL<<63))
#define PI                          (3.141592654)
#define EPS                         (1e-9)
//_________________________________________________________________________________.
const int N=1e5+9;
int x[N];

int main(){
	int n;
	scf("%d", &n);
	lp(i,1,n+1) scf("%d", x+i);
	int q;
	scf("%d", &q);
	while(q--){
		int w, h;
		scf("%d %d", &w, &h);

		x[1]=x[w]=(x[1]>x[w]?x[1]:x[w]);
		prf("%I64d\n", x[1]);
		x[1]+=h, x[w]+=(1!=w?h:0);

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   LL;
typedef unsigned long long          ULL;
typedef vector<int>                 vi;
typedef vector<vi>                  vvi;
typedef pair<int,int>               pii;
typedef pair<LL,LL>                 pll;
typedef complex<double>             point;

#define X                           real()
#define Y                           imag()
#define angle(p)                    atan2(p.Y,p.X)
#define vec(a,b)                    (b-a)
#define dot_p(v1,v2)                (conj(v1)*v2).X
#define cross_p(v1,v2)              (conj(v1)*v2).Y
#define length(p)                   hypot(p.X,p.Y)
#define lengthSqr(p)                dot_p(p,p)
#define rotateO(p,theta)            (p*exp(point(0,theta)))
#define rotateA(p,theta,about)      rotateO(vac(about,p), theta) + about
#define reflectO(p,m)               conj(p/m)*m
#define reflectA(p,p0,pm)           conj(vec(p0,p)/vec(p0,pm))*vec(p0,pm) + p0
#define scf                         scanf
#define prf                         printf
#define F_IO                        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(c)                      c.begin(),c.end()
#define sz(c)                       ((int)((c).size()))
#define pb                          push_back
#define eb                          emplace_back
#define popb                        pop_back
#define mp                          make_pair
#define xf                          first
#define ys                          second
#define lp(i,s,e)                   for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)                  for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)                for(const auto &var : c)
#define mems(c,val)                 memset(c,val,sizeof(c))
#define mod                         1000000007
#define OOi                         (~(1<<31))
#define OOl                         (~(1LL<<63))
#define PI                          (3.141592654)
#define EPS                         (1e-9)
//_________________________________________________________________________________.
const int N=1e5+9;
int x[N], n, f=1, l;
pll y[N];

bool cmp(const pll&a, const pll&b){
	return a.xf<b.xf;
}

void pre_process(){
	int f=1;
	y[f]=mp(1, x[1]);
	lp(i,2,n+1)
		if(x[i]==x[i-1]) y[f].xf=i;
		else y[++f]=mp(i, x[i]);
	l=f+1;
}

LL F(int w, int h){
	int p=lower_bound(y+f, y+l, mp(w,1),cmp)-y;
	LL ret=y[p].ys;
	LL H= 0LL + h + max(y[f].ys, y[p].ys);
	f=p; y[f].ys=H;
	return ret;
}

int main(){
	scf("%d", &n);
	lp(i,1,n+1) scf("%d", x+i);
	pre_process();
	int q;
	scf("%d", &q);
	while(q--){
		int w, h;
		scf("%d %d", &w, &h);
		prf("%I64d\n", F(w, h));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   LL;
typedef unsigned long long          ULL;
typedef vector<int>                 vi;
typedef vector<vi>                  vvi;
typedef pair<int,int>               pii;
typedef pair<LL,LL>                 pll;
typedef complex<double>             point;

#define X                           real()
#define Y                           imag()
#define angle(p)                    atan2(p.Y,p.X)
#define vec(a,b)                    (b-a)
#define dot_p(v1,v2)                (conj(v1)*v2).X
#define cross_p(v1,v2)              (conj(v1)*v2).Y
#define length(p)                   hypot(p.X,p.Y)
#define lengthSqr(p)                dot_p(p,p)
#define rotateO(p,theta)            (p*exp(point(0,theta)))
#define rotateA(p,theta,about)      rotateO(vac(about,p), theta) + about
#define reflectO(p,m)               conj(p/m)*m
#define reflectA(p,p0,pm)           conj(vec(p0,p)/vec(p0,pm))*vec(p0,pm) + p0
#define scf                         scanf
#define prf                         printf
#define F_IO                        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(c)                      c.begin(),c.end()
#define sz(c)                       ((int)((c).size()))
#define pb                          push_back
#define eb                          emplace_back
#define popb                        pop_back
#define mp                          make_pair
#define xf                          first
#define ys                          second
#define lp(i,s,e)                   for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)                  for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)                for(const auto &var : c)
#define mems(c,val)                 memset(c,val,sizeof(c))
#define mod                         1000000007
#define OOi                         (~(1<<31))
#define OOl                         (~(1LL<<63))
#define PI                          (3.141592654)
#define EPS                         (1e-9)
//_________________________________________________________________________________.
const int N=1e5+9;
int x[N], n, f=1, l;
pll y[N];

void pre_process(){
	int f=1;
	y[f]=mp(1, x[1]);
	lp(i,2,n+1)
		if(x[i]==x[i-1]) y[f].xf=i;
		else y[++f]=mp(i, x[i]);
	l=f+1;
}

LL F(int w, int h){
	int p= lower_bound(y+f, y+l, mp(w,1))-y;
	LL ret= max(y[f].ys, y[p].ys);

	LL H= ret+h ;
	f=p; y[f].ys=H;

	return ret;
}

int main(){
	scf("%d", &n);
	lp(i,1,n+1) scf("%d", x+i);
	pre_process();
	int q;
	scf("%d", &q);
	while(q--){
		int w, h;
		scf("%d %d", &w, &h);
		prf("%I64d\n", F(w, h));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   LL;
typedef unsigned long long          ULL;
typedef vector<int>                 vi;
typedef vector<vi>                  vvi;
typedef pair<int,int>               pii;
typedef pair<LL,LL>                 pll;
typedef complex<double>             point;

#define X                           real()
#define Y                           imag()
#define angle(p)                    atan2(p.Y,p.X)
#define vec(a,b)                    (b-a)
#define dot_p(v1,v2)                (conj(v1)*v2).X
#define cross_p(v1,v2)              (conj(v1)*v2).Y
#define length(p)                   hypot(p.X,p.Y)
#define lengthSqr(p)                dot_p(p,p)
#define rotateO(p,theta)            (p*exp(point(0,theta)))
#define rotateA(p,theta,about)      rotateO(vac(about,p), theta) + about
#define reflectO(p,m)               conj(p/m)*m
#define reflectA(p,p0,pm)           conj(vec(p0,p)/vec(p0,pm))*vec(p0,pm) + p0
#define scf                         scanf
#define prf                         printf
#define F_IO                        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(c)                      c.begin(),c.end()
#define sz(c)                       ((int)((c).size()))
#define pb                          push_back
#define eb                          emplace_back
#define popb                        pop_back
#define mp                          make_pair
#define xf                          first
#define ys                          second
#define lp(i,s,e)                   for(__typeof(e) i=s ; i<e ;  ++i)
#define lpr(i,e,s)                  for(__typeof(e) i=e ; i>s ;  --i)
#define lpo(var , c)                for(const auto &var : c)
#define mems(c,val)                 memset(c,val,sizeof(c))
#define mod                         1000000007
#define OOi                         (~(1<<31))
#define OOl                         (~(1LL<<63))
#define PI                          (3.141592654)
#define EPS                         (1e-9)
//_________________________________________________________________________________.
const int N=1e5+9;
int x[N], n, f=1, l;
pll y[N];

bool cmp(const pll&a, const pll&b){
	return a.xf<b.xf;
}

void pre_process(){
	int f=1;
	y[f]=mp(1, x[1]);
	lp(i,2,n+1)
		if(x[i]==x[i-1]) y[f].xf=i;
		else y[++f]=mp(i, x[i]);
	l=f+1;
}

LL F(int w, int h){
	int p= lower_bound(y+f, y+l, mp(w,1),cmp)-y;
	LL ret= max(y[f].ys, y[p].ys);

	LL H= ret+h ;
	f=p; y[f].ys=H;

	return ret;
}

int main(){
	scf("%d", &n);
	lp(i,1,n+1) scf("%d", x+i);
	pre_process();
	int q;
	scf("%d", &q);
	while(q--){
		int w, h;
		scf("%d %d", &w, &h);
		prf("%I64d\n", F(w, h));
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,ma=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma)
			ma=a[i];
	}
	int m;
	cin>>m;int p=0,f=0;
	while(m--)
	{
		int w,h;
		cin>>w>>h;

		for(int i=0;i<w;i++)
			p=max(p,a[i]);

			cout<<p<<endl;
			p=p+h;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	long long int n,ma=0;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma)
			ma=a[i];
	}
	long long int m;
	cin>>m;long int p=0,f=0;
	while(m--)
	{
		long long int w,h;
		cin>>w>>h;

			p=max(p,a[w-1]);

			cout<<p<<endl;
			p=p+h;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	long int n,ma=0;
	cin>>n;
	long int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma)
			ma=a[i];
	}
	long int m;
	cin>>m;long int p=0,f=0;
	while(m--)
	{
		int w,h;
		cin>>w>>h;

			p=max(p,a[w-1]);

			cout<<p<<endl;
			p=p+h;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,ma=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int m;
	cin>>m;
	while(m--)
	{
		int w,h;
		cin>>w>>h;
		int p=ma,f=0;
		for(int i=0;i<w;i++)
			if(a[i]>ma)
				ma=a[i];
		cout<<ma<<endl;
		for(int i=0;i<w;i++)
			a[i]=ma+h;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,ma=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma)
		ma=a[i];
	}
	int m;
	cin>>m;
	while(m--)
	{
		int w,h;
		cin>>w>>h;int p=ma,f=0;
		while(p&&f==0){
		for(int i=0;i<w&&f==0;i++)
		{
			if(a[i]==p)
			{
				cout<<a[i]<<endl;
				int v=a[i];
				for(int j=0;j<w;j++){
					//cout<<a[j]<<"/";
					a[j]=v+h;
					//cout<<a[j]<<" ";
					if(a[j]>ma)
						ma=a[j];
				}
				//cout<<endl;
				//	for(int i=0;i<n;i++)
				//		cout<<a[i]<<" ";
				//		cout<<endl;
				f++;
			}

		}
		p--;}
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	long long int n,ma=0;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma)
			ma=a[i];
	}
	long long int m;
	cin>>m;long long int p=0,f=0;
	while(m--)
	{
		long long int w,h;
		cin>>w>>h;

			p=max(p,a[w-1]);

			cout<<p<<endl;
			p=p+h;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,ma=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int m;
	cin>>m;
	while(m--)
	{
		int w,h;
		cin>>w>>h;
		int p=ma,f=0;

		for(int i=0;i<w;i++)
			if(a[i]>ma)
				ma=a[i];
		cout<<ma<<endl;
		for(int i=0;i<w;i++)
			a[i]=ma+h;
	/*	while(p&&f==0){
		for(int i=0;i<w&&f==0;i++)
		{
			if(a[i]==p)
			{
				cout<<a[i]<<endl;
				int v=a[i];
				for(int j=0;j<w;j++){
					a[j]=v+h;
					if(a[j]>ma)
						ma=a[j];
				}
				f++;
			}
		}
		p--;
		}*/
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,ma=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma)
		ma=a[i];
	}
	int m;
	cin>>m;
	while(m--)
	{
		int w,h;
		cin>>w>>h;int p=ma,f=0;
		while(p&&f==0){
		for(int i=0;i<w&&f==0;i++)
		{
			if(a[i]==p)
			{
				cout<<a[i]<<endl;
				for(int j=0;j<w;j++){
					a[j]=a[i]+h;
					if(a[j]>ma)
						ma=a[j];
				}
				f++;
			}

		}
		p--;}
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,ma=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma)
			ma=a[i];
	}
	int m;
	cin>>m;int p=0,f=0;
	while(m--)
	{
		int w,h;
		cin>>w>>h;

			p=max(p,a[w-1]);

			cout<<p<<endl;
			p=p+h;
	}
	return 0;
}


//In The Name Of God ( Of programming )

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll Maxn = 1e5 + 7;
const ll Max = 1e3 + 7;
const ll Mod = 1e9 + 7;
const ll Inf = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P_ll pair<ll, ll>
#define P_cl pair<char, ll>
#define P_lc pair<ll, char>
#define Sort( a ) sort ( a.begin(), a.end() )
#define help_me_God ios_base::sync_with_stdio ( false )

ll a[Maxn];

int main()
{
    ll n, m;
    cin >> n;
    for ( ll i = 1; i <= n; i++ )
        cin >> a[i];
    cin >> m;
    ll H = a[1];
    for ( ll i = 1; i <= m; i++ )
    {
        ll w, h;
        cin >> w >> h;
        cout << max ( H, a[w] ) << endl;
        H = max ( H, h + max ( H, a[w] ) );
    }
}


//In The Name Of God ( Of programming )

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll Maxn = 1e5 + 7;
const ll Max = 1e3 + 7;
const ll Mod = 1e9 + 7;
const ll Inf = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P_ll pair<ll, ll>
#define P_cl pair<char, ll>
#define P_lc pair<ll, char>
#define Sort( a ) sort ( a.begin(), a.end() )
#define help_me_God ios_base::sync_with_stdio ( false )

ll a[Maxn];

int main()
{
    ll n, m;
    cin >> n;
    for ( ll i = 1; i <= n; i++ )
        cin >> a[i];
    cin >> m;
    ll H = a[i]
                 for ( ll i = 1; i <= m; i++ )
    {
        ll w, h;
        cin >> w >> h;
        cout << max ( H, a[w] ) << endl;
        H = max ( H, h + max ( H, a[w] ) );
    }
}


//In The Name Of God ( Of programming )

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll Maxn = 1e5 + 7;
const ll Max = 1e3 + 7;
const ll Mod = 1e9 + 7;
const ll Inf = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P_ll pair<ll, ll>
#define P_cl pair<char, ll>
#define P_lc pair<ll, char>
#define Sort( a ) sort ( a.begin(), a.end() )
#define help_me_God ios_base::sync_with_stdio ( false )

ll a[Maxn];

int main()
{
    ll n, m;
    cin >> n;
    for ( ll i = 1; i <= n; i++ )
        cin >> a[i];
    cin >> m;
    for ( ll i = 1; i <= m; i++ )
    {
        ll w, h;
        cin >> w >> h;
        cout << a[w] << endl;
        for ( ll i = 1; i <= w; i++ )
            a[i] = a[w] + 1;
    }
}


//In The Name Of God ( Of programming )

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll Maxn = 1e5 + 7;
const ll Max = 1e3 + 7;
const ll Mod = 1e9 + 7;
const ll Inf = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P_ll pair<ll, ll>
#define P_cl pair<char, ll>
#define P_lc pair<ll, char>
#define Sort( a ) sort ( a.begin(), a.end() )
#define help_me_God ios_base::sync_with_stdio ( false )

ll a[Maxn];

int main()
{
    ll n, m;
    cin >> n;
    for ( ll i = 1; i <= n; i++ )
        cin >> a[i];
    cin >> m;
    for ( ll i = 1; i <= m; i++ )
    {
        ll w, h;
        cin >> w >> h;
        cout << a[w] << endl;
        for ( ll i = 1; i <= w; i++ )
            a[i] = a[w] + h;
    }
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;
typedef std::pair<ll,ll> pll;
typedef std::vector<pll> pvll;

int main()
{
	ll n;
	std::cin>>n;

	vll a(n+1,0);

	for(ll i=1;i<=n;++i)
	{
		std::cin>>a[i];

	}

	ll m;

	std::cin>>m;
	// std::cout<<m<<std::endl;
	pvll wh;

	vll ans(m,0);

	for(ll i=0;i<m;++i)
	{
		ll p,q;
		std::cin>>p>>q;
		wh.push_back(std::make_pair(p,q));
	}

	// std::cout<<"Done"<<std::endl;
	for(ll i=0;i<m;++i)
	{
		ll w=wh[i].first;
		ll h=wh[i].second;

		ll count=0;
		while(count<w-1)
		{
			if(a[w-1-count]>a[w])
			{
				a[w]=a[w-1-count];
				count=0;
			}

			a[w-1-count]=a[w]+h;
			++count;
		}

		ans[i]=a[w];

		a[w]+=h;
		// std::cout<<w<<" "<<a[w]<<std::endl;
	}

	std::copy(ans.begin(),ans.end(),std::ostream_iterator<ll>(std::cout,"\n"));
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;
typedef std::pair<ll,ll> pll;
typedef std::vector<pll> pvll;

int main()
{
	ll n;
	std::cin>>n;

	vll a(n+1,0);

	for(ll i=1;i<=n;++i)
	{
		std::cin>>a[i];

	}

	ll m;

	std::cin>>m;
	// std::cout<<m<<std::endl;
	pvll wh;

	// vll ans(m+1,0);

	vll b(m+1,0);
	ll max=0;

	for(ll i=1;i<=m;++i)
	{
		ll p,q;
		std::cin>>p>>q;
		// std::cout<<std::max(max,a[p])<<std::endl;
		b[i]=std::max(max,a[p]);
		a[p]=std::max(max,a[p])+q;
		max=std::max(max,a[p]);

	}

	std::copy(b.begin()+1,b.end(),std::ostream_iterator<ll>(std::cout,"\n"));

	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;
typedef std::pair<ll,ll> pll;
typedef std::vector<pll> pvll;

int main()
{
	ll n;
	std::cin>>n;

	vll a(n+1,0);

	for(ll i=1;i<=n;++i)
	{
		std::cin>>a[i];

	}

	ll m;

	std::cin>>m;
	// std::cout<<m<<std::endl;
	pvll wh;

	vll ans(m+1,0);

	for(ll i=0;i<m;++i)
	{
		ll p,q;
		std::cin>>p>>q;
		wh.push_back(std::make_pair(p,q));
	}

	// std::cout<<"Done"<<std::endl;
	ans[0]=a[wh[0].first];
	for(ll i=1;i<=m;++i)
	{
		ll w=wh[i-1].first;
		ll h=wh[i-1].second;

		ans[i]=std::max(ans[i-1]+h,a[w]);
		// ll count=0;
		// // ll temp=a[w];
		// while(count<w-1)
		// {
		// 	if(a[w-1-count]>a[w])
		// 	{
		// 		a[w]=a[w-1-count];
		// 		count=0;
		// 	}

		// 	a[w-1-count]=a[w]+h;
		// 	++count;
		// }

		// ans[i]=a[w];

		// a[w]+=h;
		// prev=ans[i];
		// std::cout<<w<<" "<<a[w]<<std::endl;
	}

	std::copy(ans.begin(),ans.end()-1,std::ostream_iterator<ll>(std::cout,"\n"));
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;
typedef std::pair<ll,ll> pll;
typedef std::vector<pll> pvll;

int main()
{
	ll n;
	std::cin>>n;

	vll a(n+1,0);

	for(ll i=1;i<=n;++i)
	{
		std::cin>>a[i];

	}

	ll m;

	std::cin>>m;
	// std::cout<<m<<std::endl;
	pvll wh;

	// vll ans(m+1,0);

	ll max=0;

	for(ll i=1;i<=m;++i)
	{
		ll p,q;
		std::cin>>p>>q;
		std::cout<<std::max(max,a[p]);
		a[p]=std::max(max,a[p])+q;
		max=std::max(max,a[p]);

	}

	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;
typedef std::pair<ll,ll> pll;
typedef std::vector<pll> pvll;

int main()
{
	ll n;
	std::cin>>n;

	vll a(n+1,0);

	for(ll i=1;i<=n;++i)
	{
		std::cin>>a[i];

	}

	ll m;

	std::cin>>m;
	// std::cout<<m<<std::endl;
	pvll wh;

	vll ans(m,0);

	for(ll i=0;i<m;++i)
	{
		ll p,q;
		std::cin>>p>>q;
		wh.push_back(std::make_pair(p,q));
	}

	// std::cout<<"Done"<<std::endl;
	for(ll i=0;i<m;++i)
	{
		ll w=wh[i].first;
		ll h=wh[i].second;
		ans[i]=a[w];

		ll count=0;
		while(count<w-1)
		{
			a[w-1-count]=a[w]+h;
			++count;
		}
		a[w]+=h;
	}

	std::copy(ans.begin(),ans.end(),std::ostream_iterator<ll>(std::cout,"\n"));
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;
typedef std::pair<ll,ll> pll;
typedef std::vector<pll> pvll;

int main()
{
	ll n;
	std::cin>>n;

	vll a(n+1,0);

	for(ll i=1;i<=n;++i)
	{
		std::cin>>a[i];

	}

	ll m;

	std::cin>>m;
	// std::cout<<m<<std::endl;
	pvll wh;

	// vll ans(m+1,0);

	ll max=0;

	for(ll i=1;i<=m;++i)
	{
		ll p,q;
		std::cin>>p>>q;
		std::cout<<std::max(max,a[p])<<std::endl;
		a[p]=std::max(max,a[p])+q;
		max=std::max(max,a[p]);

	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using LL = int64_t; //-2^63-2^63-1 10^18
const int INF = 0x3fffffff;
const double EPS = 1e-9;
const double PI = 2 * asin(1);

int g_n;
vector<LL>vll_val;

struct Segment_tree {
    vector<LL>date;
    vector<LL>lazy;
    void initial(int n) {
        date.clear(), date.resize(n << 2);
        lazy.clear(), lazy.resize(n << 2);
    }
    int ls(int root) {
        return root << 1;
    }
    int rs(int root) {
        return root << 1 | 1;
    }
    int mid(int l, int r) {
        return (l + r) >> 1;
    }
    void push_up(int root) {
        date[root] = max(date[ls(root)], date[rs(root)]);
    }
    void push_down(int root) {
        if(lazy[root]) {
            date[ls(root)] = date[rs(root)] = lazy[root];
            lazy[ls(root)] = lazy[rs(root)] = lazy[root];
            lazy[root] = 0;
        }
    }
    void change_lazy(int root, LL k) {
        date[root] = lazy[root] = k;
    }
    void built(int root, int l, int r) {
        if(l == r) {
            date[root] = vll_val[l];
            return;
        }
        built(ls(root), l, mid(l, r));
        built(rs(root), mid(l, r) + 1, r);
        push_up(root);
    }
    void update_sg(int root, int l, int r, int u, int v, LL k) {
        if(u <= l && v >= r) {
            change_lazy(root, k);
            return;
        }
        push_down(root);
        if(u <= mid(l, r))
            update_sg(ls(root), l, mid(l, r), u, v, k);
        if(v > mid(l, r))
            update_sg(rs(root), mid(l, r) + 1, r, u, v, k);
        push_up(root);
    }
    LL query(int root, int l, int r, int u, int v) {
        if(u <= l && v >= r)
            return date[root];
        push_down(root);
        if(v <= mid(l, r))
            return query(ls(root), l, mid(l, r), u, v);
        if(u > mid(l, r))
            return query(rs(root), mid(l, r) + 1, r, u, v);
        return max(query(ls(root), l, mid(l, r), u, v),
                   query(rs(root), mid(l, r) + 1, r, u, v));
    }
    void show(int root, int l, int r) {
        printf("root:%d[%d,%d]:date = %I64d,lazy = %I64d\n",
               root, l, r, date[root], lazy[root]);
        if(l == r)
            return;
        show(ls(root), l, mid(l, r));
        show(rs(root), mid(l, r) + 1, r);
    }
};
Segment_tree sg_tree;

void pretreat() {}

bool input() {
    cin >> g_n;
    if(cin.eof())
        return false;
    vll_val.clear(), vll_val.push_back(0);
    sg_tree.initial(g_n);
    for(int i = 1, t; i <= g_n; ++i) {
        scanf(" %d", &t);
        vll_val.push_back((LL)t);
    }
    return true;
}

void solve() {
    sg_tree.built(1, 1, g_n);
    int w, t, m;
    cin >> m;
    while(m--) {
        //sg_tree.show(1, 1, g_n);
        scanf(" %d %d", &w, &t);
        LL ans = sg_tree.query(1, 1, g_n, 1, w);
        printf("%I64d\n", ans);
        sg_tree.update_sg(1, 1, g_n, 1, w, ans + t);
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    pretreat();
    while(input()) {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll f[100005];// 层的高度
int main()
{
    //cout << "Hello world!" << endl;
    ll n;
    scanf("%I64d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&f[i]);
    ll m;
    scanf("%I64d",&m);
    ll tem=1;
    for(int i=0;i<m;i++)
	{
        ll w,h;
        scanf("%I64d %I64d",&w,&h);
        tem=max(f[w],tem);
        f[w]=tem+h;
        printf("%I64d\n",tem);
        tem+=h;
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxi=100010;
long long a[maxi],tree[maxi*4],add[maxi*4];

void build(int root,int l,int r)
{
    if(l==r){
        tree[root]=a[l];
        return;
    }
    int m=(l+r)/2;
    build(root*2,l,m);
    build(root*2+1,m+1,r);
    tree[root]=max(tree[root*2],tree[root*2+1]);
}

void pushdown(int root)
{
    if(add[root]){
       add[root*2]=add[root*2+1]=add[root];
       tree[root*2]=tree[root*2+1]=add[root];
       add[root]=0;
    }
}

void update(int root,int L,int R,int l,int r,int v)
{
    if(l>=L&&r<=R){
        tree[root]=v;
        add[root]=v;
        return;
    }
    int m=(l+r)/2;
    pushdown(root);
    if(L<=m)update(root*2,L,R,l,m,v);
    if(R>m)update(root*2+1,L,R,m+1,r,v);
    tree[root]=max(tree[root*2+1],tree[root*2]);
    return;
}

long long query(int root,int L,int R,int l,int r)
{
    if(l>=L&&r<=R){
        return tree[root];
    }
    long long ans=0;
    pushdown(root);
    int m=(l+r)/2;
    if(L<=m)
        ans=max(ans,query(root*2,L,R,l,m));
    if(R>m)
        ans=max(ans,query(root*2+1,L,R,m+1,r));
    return ans;
}

int main()
{
    int n,m;
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    build(1,1,n);
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        long long ans=query(1,1,x,1,n);
        printf("%lld\n",ans);
        update(1,1,x,1,n,(long long)y+ans);
    }
    return 0;
}


#include<iostream>

using namespace std;

long long a[1000000],i,j,n,m,h1,L,h,w;
int main()
{
    cin>>n;
    for (i=1; i<=n; i++)
        cin>>a[i];
    cin>>m;
    for (i=0; i<m; i++)
    {
        cin>>w>>h;
        L=max(L+h1,a[w]);
        cout<<L<<endl;
       h1=h;
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
int main()
{
    ll n, m, l, w, h, t;
    while (cin >> n)
    {
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        cin >> m;
        l = 1;
        for (int i = 0; i < m; i++)
        {
            cin >> w >> h;
            t = max(a[w], l);
            cout << t << endl;
            l = t + h;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long long number[100001],n,m,w,h,k;
    while(cin>>n)
    {
        number[0]=0;
        for(int i=1;i<=n;i++)
        {
            cin>>number[i];
        }
        cin>>m;
        k=1;
        while(m--)
        {
            cin>>w>>h;
            k=max(k,number[w]);
            cout<<k<<endl;
            k+=h;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, m, w, h, a[100005], t[100005], z[100005];

void build (int v, int L, int R)
{
    if (L==R)
    {
        t[v]=a[L];
        return;
    }
    int md=(L+R)/2;
    build (v*2, L, md);
    build (v*2+1, md+1, R);
    t[v]=max(t[v*2], t[v*2+1]);
}

int sum(int v, int tl, int tr, int l, int r)
{
	if (tl > r || tr < l)
		return 0;
	if (tl >= l && tr <= r)
		return t[v];
	int mid = tl + tr >> 1;
	int k = z[v];
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] = (mid - tl + 1) * k;
		t[v + v + 1] = (r - mid) * k;
		z[v] = 0;
	}
	return max(sum(v + v, tl, mid, l, r), sum(v + v + 1, mid + 1, tr, l, r));
}

void upd(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > r || tr < l)
		return;
	if (tl >= l && tr <= r)
	{
		z[v] = x;
		t[v] = (tr + tl - 1) * x;
		return;
	}
	int mid = tl + tr >> 1;
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] = (mid - tl + 1) * z[v];
		t[v + v + 1] = (r - mid) * z[v];
		z[v] = 0;
	}
	upd(v + v, tl, mid, l, r, x);
	upd(v + v + 1, mid + 1, tr, l, r, x);
	t[v] = max(t[v * 2] ,t[v * 2 + 1]);
}

main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    build (1, 1, n);
    cin >> m;
    for (int i=1;i<=m;i++)
    {
        cin >> w >> h;
        int s=sum(1, 1, n, 1, w);
        cout << s << "\n";
        upd(1, 1, n, 1, w, s+h);
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, m, w, h, a[1000005], t[4*1000005], z[4*1000005];

void build (int v, int L, int R)
{
    if (L==R)
    {
        t[v]=a[L];
        return;
    }
    int md=(L+R)/2;
    build (v*2, L, md);
    build (v*2+1, md+1, R);
    t[v]=max(t[v*2], t[v*2+1]);
}

int get(int v, int tl, int tr, int l, int r)
{
	if (tl > r || tr < l)
		return -999999999;
	if (tl >= l && tr <= r)
		return t[v];
	int mid = tl + tr >> 1;
	int k = z[v];
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] =  z[v];
		t[v + v + 1] =  z[v];
		z[v] = 0;
	}
	return max(get(v + v, tl, mid, l, r), get(v + v + 1, mid + 1, tr, l, r));
}

void upd(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > r || tr < l)
		return;
	if (tl >= l && tr <= r)
	{
		z[v] = x;
		t[v] = x;
		return;
	}
	int mid = tl + tr >> 1;
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] = z[v];
		t[v + v + 1] = z[v];
		z[v] = 0;
	}
	upd(v + v, tl, mid, l, r, x);
	upd(v + v + 1, mid + 1, tr, l, r, x);
	t[v] = max(t[v * 2] , t[v * 2 + 1]);
}

main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    build (1, 1, n);
    cin >> m;
    for (int i=1;i<=m;i++)
    {
        cin >> w >> h;
        int s=get(1, 1, n, 1, w);
        cout << s << " ";
        upd(1, 1, n, 1, w, s+h);
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, m, w, h, a[100005], t[100005], z[100005];

void build (int v, int L, int R)
{
    if (L==R)
    {
        t[v]=a[L];
        return;
    }
    int md=(L+R)/2;
    build (v*2, L, md);
    build (v*2+1, md+1, R);
    t[v]=max(t[v*2], t[v*2+1]);
}

int get(int v, int tl, int tr, int l, int r)
{
	if (tl > r || tr < l)
		return -999999999;
	if (tl >= l && tr <= r)
		return t[v];
	int mid = tl + tr >> 1;
	int k = z[v];
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] =  z[v ];
		t[v + v + 1] =  z[v];
		z[v] = 0;
	}
	return max(get(v + v, tl, mid, l, r), get(v + v + 1, mid + 1, tr, l, r));
}

void upd(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > r || tr < l)
		return;
	if (tl >= l && tr <= r)
	{
		z[v] = x;
		t[v] = x;
		return;
	}
	int mid = tl + tr >> 1;
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] = z[v];
		t[v + v + 1] = z[v];
		z[v] = 0;
	}
	upd(v + v, tl, mid, l, r, x);
	upd(v + v + 1, mid + 1, tr, l, r, x);
	t[v] = max(t[v * 2] , t[v * 2 + 1]);
}

main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    build (1, 1, n);
    cin >> m;
    for (int i=1;i<=m;i++)
    {
        cin >> w >> h;
        int s=get(1, 1, n, 1, w);
        cout << s << " ";
        upd(1, 1, n, 1, w, s+h);
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, m, w, h, a[100005], t[100005], z[100005];

void build (int v, int L, int R)
{
    if (L==R)
    {
        t[v]=a[L];
        return;
    }
    int md=(L+R)/2;
    build (v*2, L, md);
    build (v*2+1, md+1, R);
    t[v]=max(t[v*2], t[v*2+1]);
}

int get(int v, int tl, int tr, int l, int r)
{
	if (tl > r || tr < l)
		return -999999999;
	if (tl >= l && tr <= r)
		return t[v];
	int mid = tl + tr >> 1;
	int k = z[v];
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] = (mid - tl + 1) * k;
		t[v + v + 1] = (r - mid) * k;
		z[v] = 0;
	}
	return max(get(v + v, tl, mid, l, r), get(v + v + 1, mid + 1, tr, l, r));
}

void upd(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > r || tr < l)
		return;
	if (tl >= l && tr <= r)
	{
		z[v] = x;
		t[v] = x;
		return;
	}
	int mid = tl + tr >> 1;
	if (z[v] != 0)
	{
		z[v + v] = z[v];
		z[v + v + 1] = z[v];
		t[v + v] = (mid - tl + 1) * z[v];
		t[v + v + 1] = (r - mid) * z[v];
		z[v] = 0;
	}
	upd(v + v, tl, mid, l, r, x);
	upd(v + v + 1, mid + 1, tr, l, r, x);
	t[v] = max(t[v * 2] , t[v * 2 + 1]);
}

main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    build (1, 1, n);
    cin >> m;
    for (int i=1;i<=m;i++)
    {
        cin >> w >> h;
        int s=get(1, 1, n, 1, w);
        cout << s << " ";
        upd(1, 1, n, 1, w, s+h);
    }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<long long int> v;
    long long int a[n];

    for(int i=0; i<n;i++){
        long long int y;
        cin>>y;
        v.push_back(y);
    }

    a[0] = v[0];

    for(int i=1; i<n;i++){
        a[i] = max(a[i-1],v[i]);
    }

    int m;
    cin>>m;
    long long int l = 0;
    long long int w,h2,h1=0;
    for(int i=0;i<m;i++){
        cin>>w>>h2;
        l = max(l+h1, a[w-1]);
        cout<<l<<"\n";
        h1 = h2;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<long long int> v;
    long long int a[n];

    for(int i=0; i<n;i++){
        long long int y;
        cin>>y;
        v.push_back(y);
    }

    a[0] = v[0];

    for(int i=1; i<n;i++){
        a[i] = max(a[i-1],v[i]);
    }

    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        long long int w,h;
        cin>>w>>h;
        for(int i=1; i<w;i++){
            a[i] = max(a[i-1],a[i]);
        }
        cout<<a[w-1]<<"\n";
        for(int j=0;j<w;j++){
            a[j] = a[w-1]+h;
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<long long int> v;
    long long int a[n];

    for(int i=0; i<n;i++){
        long long int y;
        cin>>y;
        v.push_back(y);
    }

    a[0] = v[0];

    for(int i=1; i<n;i++){
        a[i] = max(a[i-1],v[i]);
    }

    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        long long int w,h;
        cin>>w>>h;

        cout<<a[w-1]<<"\n";
        for(int j=0;j<w;j++){
            a[j] = a[w-1]+h;
        }
        for(int i=1; i<n;i++){
        a[i] = max(a[i-1],v[i]);
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<long long int> v;
    long long int a[n];

    for(int i=0; i<n;i++){
        long long int y;
        cin>>y;
        v.push_back(y);
    }

    a[0] = v[0];

    for(int i=1; i<n;i++){
        a[i] = max(a[i-1],v[i]);
    }

    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        long long int w,h;
        cin>>w>>h;

        cout<<a[w-1]<<"\n";
        for(int j=0;j<w;j++){
            a[j] = a[w-1]+h;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> ls;
ll gogo(ll w,ll h){
	ll mx=0;
	for(ll i=0;i<w;i++){
		mx=(ls[i]>mx? ls[i]:mx);
		}
	for(ll i=0;i<w;i++)
		ls[i]=(mx+h);
	return mx;
}
int main(){
	ll n;cin>>n;
	for(ll u=0;u<n;u++){
		int an;cin>>an;
		ls.push_back(an);}
	ll b;cin>>b;ll ans[b];
	for(ll i=0;i<b;i++){
		ll w,h;cin>>w>>h;
		ans[i]=(gogo(w,h));
	}
	for(ll i:ans) cout<<i<<"\n";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> ls;
ll gogo(ll w,ll h){
	ll ind=0,o=0,mx=0;
	for(ll i=0;i<w;i++){
		ind=(ls[i]>mx? o:ind);
		mx=(ls[i]>mx? ls[i]:mx);
		o++;}
	for(ll i=0;i<w;i++)
		ls[i]=(ls[ind]+h);
	return mx;
}
int main(){
	ll n;cin>>n;
	for(ll u=0;u<n;u++){
		int an;cin>>an;
		ls.push_back(an);}
	ll b;cin>>b;ll ans[b];
	for(ll i=0;i<b;i++){
		ll w,h;cin>>w>>h;
		ans[i]=(gogo(w,h));
	}
	for(ll i:ans) cout<<i<<"\n";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll an=0,l=0,n;
	cin>>n;ll ls[n];
	for(ll u=0;u<n;u++) cin>>ls[u];
	ll b;cin>>b;
	for(ll i=0;i<b;i++){
		ll w,h;cin>>w>>h;
                an=max(an,ls[w-1]);
                cout<<an<<"\n";
                an=an+h;
         }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

class  SegTree{
    vll st;
    vll lz;
    int size;

    int el_neutro = -inf;

    int f(int a, int b){
        return max(a,b);
    }
    void propagate(int sti, int stl, int str){
        if(lz[sti]){
            st[sti] = lz[sti];
            if(stl != str)
            {
                lz[sti*2 + 1] += lz[sti];
                lz[sti*2 + 2] += lz[sti];
            }
            lz[sti] = 0;
        }
    }

    ll query(int sti, int stl, int str, int l, int r){
        propagate(sti, stl, str);

        if(str < l || r < stl)
            return el_neutro;

        if(stl >= l and str <= r)
            return st[sti];

        int mid = (str+stl)/2;

        return f(query(sti*2+1,stl,mid,l,r),query(sti*2+2,mid+1,str,l,r));
    }

    void update_range(int sti, int stl, int str, int l,int r, ll amm){
        propagate(sti, stl, str);

        if(stl >= l and str <= r){
            lz[sti] += amm;
            propagate(sti, stl, str);
            return;
        }

        if(stl > r  or str < l)
            return;

        int mid = (stl + str)/2;

        update_range(sti*2+1,stl,mid,l,r,amm);
        update_range(sti*2+2,mid+1,str,l,r,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    void update(int sti, int stl, int str, int i, ll amm){
        propagate(sti, stl, str);
        if(stl == i and str == i){
            st[sti] = amm;
            return;
        }

        if(stl > i or str < i)
            return;

        int mid = (stl + str)/2;

        update(sti*2+1,stl,mid,i,amm);
        update(sti*2+2,mid+1,str,i,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    public:
        SegTree(int n):  st(4*n,0), lz(4*n,0){size = n;}
        ll query(int l, int  r){return query(0,0,size-1,l,r);}
        void update_range(int l, int r, ll amm){update_range(0,0,size-1,l,r,amm);}
        void update(int i, ll amm){update(0,0,size-1,i,amm);}
};

int main(){

	int n;
	sf1(n);

	SegTree st(n);

	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);
		st.update(i,x);
	}

	int q;
	sf1(q);

	for (int i = 0; i < q; ++i)
	{
		int a,b;
		sf2(a,b);

		ll hit = st.query(0,a-1);

		printf("%lld\n",hit);
		st.update_range(0,a-1,hit+b);
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

class  SegTree{
    vll st;
    vll lz;
    int size;

    int el_neutro = -inf;

    ll f(ll a, ll b){
        return max(a,b);
    }
    void propagate(int sti, int stl, int str){
        if(lz[sti]){
            st[sti] = lz[sti];
            if(stl != str)
            {
                lz[sti*2 + 1] = lz[sti];
                lz[sti*2 + 2] = lz[sti];
            }
            lz[sti] = 0;
        }
    }

    ll query(int sti, int stl, int str, int l, int r){
        propagate(sti, stl, str);

        if(str < l || r < stl)
            return el_neutro;

        if(stl >= l and str <= r)
            return st[sti];

        int mid = (str+stl)/2;

        return f(query(sti*2+1,stl,mid,l,r),query(sti*2+2,mid+1,str,l,r));
    }

    void update_range(int sti, int stl, int str, int l,int r, ll amm){
        propagate(sti, stl, str);

        if(stl >= l and str <= r){
            lz[sti] = amm;
            propagate(sti, stl, str);
            return;
        }

        if(stl > r  or str < l)
            return;

        int mid = (stl + str)/2;

        update_range(sti*2+1,stl,mid,l,r,amm);
        update_range(sti*2+2,mid+1,str,l,r,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    void update(int sti, int stl, int str, int i, ll amm){
        propagate(sti, stl, str);
        if(stl == i and str == i){
            st[sti] = amm;
            return;
        }

        if(stl > i or str < i)
            return;

        int mid = (stl + str)/2;

        update(sti*2+1,stl,mid,i,amm);
        update(sti*2+2,mid+1,str,i,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    public:
        SegTree(int n):  st(4*n,0), lz(4*n,0){size = n;}
        ll query(int l, int  r){return query(0,0,size-1,l,r);}
        void update_range(int l, int r, ll amm){update_range(0,0,size-1,l,r,amm);}
        void update(int i, ll amm){update(0,0,size-1,i,amm);}
};

int main(){

	int n;
	sf1(n);

	SegTree st(n);

	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);
		st.update(i,x);
	}

	int q;
	sf1(q);

	for (int i = 0; i < q; ++i)
	{
		int a,b;
		sf2(a,b);

		ll hit = st.query(0,a-1);

		printf("%lld\n",hit);
		st.update_range(0,a-1,hit+b);
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

class  SegTree{
    vi st;
    vi lz;
    int size;

    int el_neutro = -inf;

    int f(int a, int b){
        return max(a,b);
    }
    void propagate(int sti, int stl, int str){
        if(lz[sti]){
            st[sti] = lz[sti];
            if(stl != str)
            {
                lz[sti*2 + 1] += lz[sti];
                lz[sti*2 + 2] += lz[sti];
            }
            lz[sti] = 0;
        }
    }

    int query(int sti, int stl, int str, int l, int r){
        propagate(sti, stl, str);

        if(str < l || r < stl)
            return el_neutro;

        if(stl >= l and str <= r)
            return st[sti];

        int mid = (str+stl)/2;

        return f(query(sti*2+1,stl,mid,l,r),query(sti*2+2,mid+1,str,l,r));
    }

    void update_range(int sti, int stl, int str, int l,int r, int amm){
        propagate(sti, stl, str);

        if(stl >= l and str <= r){
            lz[sti] += amm;
            propagate(sti, stl, str);
            return;
        }

        if(stl > r  or str < l)
            return;

        int mid = (stl + str)/2;

        update_range(sti*2+1,stl,mid,l,r,amm);
        update_range(sti*2+2,mid+1,str,l,r,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    void update(int sti, int stl, int str, int i, int amm){
        propagate(sti, stl, str);
        if(stl == i and str == i){
            st[sti] = amm;
            return;
        }

        if(stl > i or str < i)
            return;

        int mid = (stl + str)/2;

        update(sti*2+1,stl,mid,i,amm);
        update(sti*2+2,mid+1,str,i,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    public:
        SegTree(int n):  st(4*n,0), lz(4*n,0){size = n;}
        int query(int l, int  r){return query(0,0,size-1,l,r);}
        void update_range(int l, int r, int amm){update_range(0,0,size-1,l,r,amm);}
        void update(int i, int amm){update(0,0,size-1,i,amm);}
};

int main(){

	int n;
	sf1(n);

	SegTree st(n);

	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);
		st.update(i,x);
	}

	int q;
	sf1(q);

	for (int i = 0; i < q; ++i)
	{
		int a,b;
		sf2(a,b);

		int hit = st.query(0,a-1);

		printf("%d\n",hit);
		st.update_range(0,a-1,hit+b);
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

class  SegTree{
    vll st;
    vll lz;
    int size;

    int el_neutro = -inf;

    int f(int a, int b){
        return max(a,b);
    }
    void propagate(int sti, int stl, int str){
        if(lz[sti]){
            st[sti] = lz[sti];
            if(stl != str)
            {
                lz[sti*2 + 1] = lz[sti];
                lz[sti*2 + 2] = lz[sti];
            }
            lz[sti] = 0;
        }
    }

    ll query(int sti, int stl, int str, int l, int r){
        propagate(sti, stl, str);

        if(str < l || r < stl)
            return el_neutro;

        if(stl >= l and str <= r)
            return st[sti];

        int mid = (str+stl)/2;

        return f(query(sti*2+1,stl,mid,l,r),query(sti*2+2,mid+1,str,l,r));
    }

    void update_range(int sti, int stl, int str, int l,int r, ll amm){
        propagate(sti, stl, str);

        if(stl >= l and str <= r){
            lz[sti] = amm;
            propagate(sti, stl, str);
            return;
        }

        if(stl > r  or str < l)
            return;

        int mid = (stl + str)/2;

        update_range(sti*2+1,stl,mid,l,r,amm);
        update_range(sti*2+2,mid+1,str,l,r,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    void update(int sti, int stl, int str, int i, ll amm){
        propagate(sti, stl, str);
        if(stl == i and str == i){
            st[sti] = amm;
            return;
        }

        if(stl > i or str < i)
            return;

        int mid = (stl + str)/2;

        update(sti*2+1,stl,mid,i,amm);
        update(sti*2+2,mid+1,str,i,amm);
        st[sti] = f(st[sti*2+1],st[sti*2+2]);
    }

    public:
        SegTree(int n):  st(4*n,0), lz(4*n,0){size = n;}
        ll query(int l, int  r){return query(0,0,size-1,l,r);}
        void update_range(int l, int r, ll amm){update_range(0,0,size-1,l,r,amm);}
        void update(int i, ll amm){update(0,0,size-1,i,amm);}
};

int main(){

	int n;
	sf1(n);

	SegTree st(n);

	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);
		st.update(i,x);
	}

	int q;
	sf1(q);

	for (int i = 0; i < q; ++i)
	{
		int a,b;
		sf2(a,b);

		ll hit = st.query(0,a-1);

		printf("%lld\n",hit);
		st.update_range(0,a-1,hit+b);
	}

}


#include<bits/stdc++.h>
using namespace std;

const int maxn=200005;
int n,m;
int a[maxn];
long long t[maxn*4],lazy[maxn*4];
int lf,rg,v;

void pushup(int pos)
{
	t[pos]=max(t[pos*2],t[pos*2+1]);
}

void pushdown(int pos)
{
	if(lazy[pos])
	{
		lazy[pos*2]=lazy[pos];
		lazy[pos*2+1]=lazy[pos];
		t[pos*2]=lazy[pos];
		t[pos*2+1]=lazy[pos];
		lazy[pos]=0;//注意清零 不然会重复下推 导致错误
	}

}

void build(int l,int r,int pos)
{
	if(l==r)
	{
		t[pos]=a[l];
		return ;
	}
	build(l,l+r>>1,2*pos);
	build((l+r>>1)+1,r,pos*2+1);
	pushup(pos);
}

long long query(int L,int R,int l,int r,int pos)
{
	int m=l+r>>1;
	if(l>=L&&r<=R)
	{
		return t[pos];
	}
	pushdown(pos);
	long long tmp=-1;
	if(L<=m)
	{
		tmp=max(tmp,query(L,R,l,m,pos*2));
	}
	if(R>m)
	{
		tmp=max(tmp,query(L,R,m+1,r,pos*2+1));
	}
	return tmp;
}

void add(int L,int R,int l,int r,int pos,long long val)
{
	int m=l+r>>1;
	if(l>=L&&r<=R)
	{
		t[pos]=val;
		lazy[pos]=t[pos];
		return ;//注意
	}
	pushdown(pos);
	if(L<=m)
	{
		add(L,R,l,m,pos*2,val);
	}
	if(R>m)
	{
		add(L,R,m+1,r,pos*2+1,val);
	}
	pushup(pos);
}

int main()
{

	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d",a+i);
	}
	scanf("%d",&m);
	build(1,n,1);
	for(int i=1; i<=m; i++)
	{
		int w,h;
		scanf("%d%d",&w,&h);
		long long hv=query(1,w,1,n,1);
		printf("%I64d\n",hv);
		add(1,w,1,n,1,hv+h);//注意操作
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn=200005;
int n,m;
int a[maxn];
long long t[maxn*4],lazy[maxn*4];
int lf,rg,v;

void pushup(int pos)
{
	t[pos]=max(t[pos*2],t[pos*2+1]);
}

void pushdown(int pos)
{
	if(lazy[pos])
	{
		lazy[pos*2]=lazy[pos];
		lazy[pos*2+1]=lazy[pos];
		t[pos*2]=lazy[pos];
		t[pos*2+1]=lazy[pos];
		lazy[pos]=0;//注意清零 不然会重复下推 导致错误
	}

}

void build(int l,int r,int pos)
{
	if(l==r)
	{
		t[pos]=a[l];
		return ;
	}
	build(l,l+r>>1,2*pos);
	build((l+r>>1)+1,r,pos*2+1);
	pushup(pos);
}

long long query(int L,int R,int l,int r,int pos)
{
	int m=l+r>>1;
	if(l>=L&&r<=R)
	{
		return t[pos];
	}
	pushdown(pos);
	long long tmp=-1;
	if(L<=m)
	{
		tmp=max(tmp,query(L,R,l,m,pos*2));
	}
	if(R>m)
	{
		tmp=max(tmp,query(L,R,m+1,r,pos*2+1));
	}
	return tmp;
}

void add(int L,int R,int l,int r,int pos,int val)
{
	int m=l+r>>1;
	if(l>=L&&r<=R)
	{
		t[pos]=val;
		lazy[pos]=t[pos];
		return ;//注意
	}
	pushdown(pos);
	if(L<=m)
	{
		add(L,R,l,m,pos*2,val);
	}
	if(R>m)
	{
		add(L,R,m+1,r,pos*2+1,val);
	}
	pushup(pos);
}

int main()
{

	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d",a+i);
	}
	scanf("%d",&m);
	build(1,n,1);
	for(int i=1; i<=m; i++)
	{
		int w,h;
		scanf("%d%d",&w,&h);
		long long hv=query(1,w,1,n,1);
		printf("%I64d\n",hv);
		add(1,w,1,n,1,hv+h);//注意操作
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn=200005;
int n,m;
int a[maxn];
long long t[maxn*4],lazy[maxn*4];
int lf,rg,v;

void pushup(int pos)
{
	t[pos]=max(t[pos*2],t[pos*2+1]);
}

void pushdown(int pos)
{
	if(lazy[pos])
	{
		lazy[pos*2]=lazy[pos];
		lazy[pos*2+1]=lazy[pos];
		t[pos*2]=lazy[pos];
		t[pos*2+1]=lazy[pos];
	}

}

void build(int l,int r,int pos)
{
	if(l==r)
	{
		t[pos]=a[l];
		return ;
	}
	build(l,l+r>>1,2*pos);
	build((l+r>>1)+1,r,pos*2+1);
	pushup(pos);
}

long long query(int L,int R,int l,int r,int pos)
{
	int m=l+r>>1;
	if(l>=L&&r<=R)
	{
		return t[pos];
	}
	pushdown(pos);
	long long tmp=-1;
	if(L<=m)
	{
		tmp=max(tmp,query(L,R,l,m,pos*2));
	}
	if(R>m)
	{
		tmp=max(tmp,query(L,R,m+1,r,pos*2+1));
	}
	return tmp;
}

void add(int L,int R,int l,int r,int pos,int val)
{
	int m=l+r>>1;
	if(l>=L&&r<=R)
	{
		t[pos]=val;
		lazy[pos]=t[pos];
		return ;//注意
	}
	pushdown(pos);
	if(L<=m)
	{
		add(L,R,l,m,pos*2,val);
	}
	if(R>m)
	{
		add(L,R,m+1,r,pos*2+1,val);
	}
	pushup(pos);
}

int main()
{

	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d",a+i);
	}
	scanf("%d",&m);
	build(1,n,1);
	for(int i=1; i<=m; i++)
	{
		int w,h;
		scanf("%d%d",&w,&h);
		long long hv=query(1,w,1,n,1);
		printf("%I64d\n",hv);
		add(1,w,1,n,1,hv+h);//注意操作
	}
	return 0;
}