#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n, a[maxn], dp[10][maxn];
void initrmq() {
for (int i = 1; i <= n; i++) dp[0][i] = a[i];
for (int i = 1; (1<<i) <= n; i++) {
for (int j = 1; j + (1<<i) - 1 <= n; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + (1<<(i-1))]);
}
}
}
int query(int l, int r) {
int k = log(r - l + 1) / log(2);
cout << k << "===" << endl;
return max(dp[k][l], dp[k][r - (1<<k) + 1]);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
initrmq();
int l, r;
while (~scanf("%d %d", &l, &r)) {
cout << query(l, r) << endl;
}
return 0;
}