#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long long linf = (1ll << 62) - 1;
const int N = 5e3 + 100;
int n;
int a[N], na[N];
int result[N][N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      result[j][j + i] = a[j];
    }
    for (int j = 0; j < n - i - 1; j++) {
      na[j] = a[j] ^ a[j + 1];
    }
    for (int j = 0; j < n - i - 1; j++) {
      a[j] = na[j];
    }
  }
  for (int len = 2; len <= n; len++) {
    for (int i = 0; i <= n - len; i++) {
      int l = i, r = i + len - 1;
      result[l][r] = max(result[l][r], max(result[l + 1][r], result[l][r - 1]));
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r), l--, r--;
    printf("%d\n", result[l][r]);
  }
  return 0;
}
