#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];

    vector<int> R1(N),R2(N);
    for(int i=0;i<N;){
        int i0=i++;
        while(i<N and a[i-1]<=a[i]) i++;
        for(int j=i0;j<i;j++){
            R1[j]=i;
        }
    }
    for(int i=0;i<N;i++) a[i]*=-1;
    for(int i=0;i<N;){
        int i0=i++;
        while(i<N and a[i-1]<=a[i]) i++;
        for(int j=i0;j<i;j++){
            R2[j]=i;
        }
    }
    // for(int i=0;i<N;i++) cout<<R1[i]<<' '; cout<<endl;
    // for(int i=0;i<N;i++) cout<<R2[i]<<' '; cout<<endl;

    int Q; cin>>Q;
    while(Q--){
        int l,r; cin>>l>>r;
        cout<<(r<R1[l])<<' '<<(r<R2[l])<<endl;
    }
    return 0;
}