#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; V A(n+2); V B; B.push_back(0); rep(i,n){ cin>>A[i+1]; if(A[i+1]==0) B.push_back(i+1); } B.push_back(n+1); V S(n+2); rep(i,n+1) S[i+1]=S[i]+A[i]; int q; cin>>q; while(q--){ ll x,b; cin>>x>>b; if(A[x]==0){ auto r=upper_bound(ALL(B),x)-B.begin(); cout<