#include <bits/stdc++.h>
using namespace std;
int a[5007];
int kj[37][5007];
int dp[5007][5007];
int hh[5007][5007];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < 30; i++) {
    kj[i][0] = 0;
    for (int j = 1; j <= n; j++) {
      kj[i][j] = ((a[j] & (1 << i)) != 0) + kj[i][j - 1];
    }
  }
  int q, l, r;
  scanf("%d", &q);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - i + 1; j++) {
      dp[j][i + j] = max(dp[j][i + j - 1], dp[j + 1][i + j]);
      if (i == 1) {
        dp[j][i + j] = a[j];
        hh[j][i + j] = a[j];
      } else {
        hh[j][i + j] = hh[j][i + j - 1] ^ hh[j + 1][i + j];
        dp[j][i + j] = max(dp[j][i + j], hh[j][i + j]);
      }
    }
  }
  while (q != 0) {
    q--;
    scanf("%d%d", &l, &r);
    printf("%d\n", dp[l][r + 1]);
  }
  return 0;
}
