#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, a[N][N], maks[N][N], q;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    scanf("%d", &a[n - 1][i]);
    maks[n - 1][i] = a[n - 1][i];
  }
  for (int i = (n - 1) - 1; i >= 0; --i) {
    for (int j = 0; j < (i + 1); ++j) {
      a[i][j] = a[i + 1][j] ^ a[i + 1][j + 1];
      maks[i][j] = max(a[i][j], max(maks[i + 1][j], maks[i + 1][j + 1]));
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < (q); ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l;
    --r;
    printf("%d\n", maks[n - 1 - (r - l)][l]);
  }
}
