#include <bits/stdc++.h>
using namespace std;
int s[5005][5005];
int ans[5005][5005];
int a[5005];
int hibit(int l) {
  int ret = 1;
  while (l) {
    ret <<= 1;
    l >>= 1;
  }
  ret >>= 1;
  return ret;
}
int main(void) {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int l = 1; l <= n; l++) {
    for (int i = 0; i < n; i++) {
      if (l == 1) {
        s[i][i] = a[i];
        continue;
      }
      int st = i, ed = i + l - 1;
      if (ed >= n) continue;
      int ll = l - hibit(l - 1);
      s[st][ed] = s[st][st + (ll - 1)] ^ s[ed - (ll - 1)][ed];
    }
  }
  for (int l = 1; l <= n; l++)
    for (int i = 0; i < n; i++) {
      if (l == 1)
        ans[i][i] = s[i][i];
      else {
        int j = i + l - 1;
        ans[i][j] = s[i][j];
        ans[i][j] = max(ans[i][j], ans[i][j - 1]);
        ans[i][j] = max(ans[i][j], ans[i + 1][j]);
      }
    }
  int q;
  scanf("%d", &q);
  for (; q > 0; q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    printf("%d\n", ans[l][r]);
  }
  return 0;
}
