#include <bits/stdc++.h>   using namespace std;   struct re {     long long x[300300];     long long up[300300];     bool f[300300];   };   int o;   re rmq;   void f_read() {     int i, n, a[100100];     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     o = 1;     memset(rmq.x, 0, sizeof(rmq.x));     memset(rmq.up, 0, sizeof(rmq.up));     memset(rmq.f, 0, sizeof(rmq.f));     while (o < n) o *= 2;     for (i = 0; i < n; ++i) rmq.x[i + o] = a[i];     for (i = o - 1; i > 0; --i)       rmq.x[i] = ((rmq.x[i * 2]) < (rmq.x[i * 2 + 1]) ? (rmq.x[i * 2 + 1])                                                       : (rmq.x[i * 2]));   }   void RPUSH(int v) {     if (!rmq.f[v]) return;     rmq.f[v * 2] = 1;     rmq.up[v * 2] = rmq.up[v];     rmq.f[v * 2 + 1] = 1;     rmq.up[v * 2 + 1] = rmq.up[v];     rmq.x[v] = rmq.up[v];     rmq.f[v] = 0;   }   long long RMAX(int l, int r, int v = 1, int cl = 1, int cr = o) {     if (l > r) return 0;     if (l == cl && r == cr) {       if (rmq.f[v])         return rmq.up[v];       else         return rmq.x[v];     }     RPUSH(v);     int t = (cl + cr) >> 1;     long long a = RMAX(l, ((r) > (t) ? (t) : (r)), v * 2, cl, t),               b = RMAX(((t + 1) < (l) ? (l) : (t + 1)), r, v * 2 + 1, t + 1, cr);     return ((a) < (b) ? (b) : (a));   }   long long RADD(int l, int r, long long d, int v = 1, int cl = 1, int cr = o) {     if (l > r)       if (rmq.f[v])         return rmq.up[v];       else         return rmq.x[v];     if (l == cl && r == cr) {       rmq.f[v] = 1;       rmq.up[v] = d;       return d;     }     RPUSH(v);     int t = (cl + cr) >> 1;     long long a = RADD(l, ((t) > (r) ? (r) : (t)), d, v * 2, cl, t),               b = RADD(((t + 1) < (l) ? (l) : (t + 1)), r, d, v * 2 + 1, t + 1,                        cr);     rmq.x[v] = ((a) < (b) ? (b) : (a));     return rmq.x[v];   }   int main() {     f_read();     int i, m, w, h;     cin >> m;     for (i = 0; i < m; ++i) {       cin >> w >> h;       long long t = RMAX(1, w);       cout << t << endl;       RADD(1, w, h + t);     }     return 0;   }   