#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 10;
const int MOD = 1e9 + 7;
const long long LLMAX = 2e18;
priority_queue<int, vector<int>, greater<int> > qu;
priority_queue<int, vector<int>, less<int> > qd;
void test() {
  FILE *fin = NULL, *fout = NULL;
  fin = freopen("D:\\Project__C&C++\\testdata.in", "r", stdin);
  fout = freopen("D:\\Project__C&C++\\testdata.out", "w", stdout);
}
int dp[MAXN][MAXN], a[MAXN][MAXN];
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i][i]), dp[i][i] = a[i][i];
  for (int j = 1; j <= n; j++)
    for (int i = 1; i <= n - j; i++) {
      a[i][j + i] = a[i + 1][j + i] ^ a[i][j + i - 1];
      dp[i][j + i] = max(a[i][j + i], max(dp[i + 1][j + i], dp[i][j + i - 1]));
    }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    cout << dp[x][y] << endl;
  }
  return 0;
}
