#include <bits/stdc++.h>
using namespace std;
const int maxn = 5100;
int n;
unsigned long long arr[maxn], dp[maxn][maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%llu", arr + i);
    dp[i][i] = arr[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i > n - j + 1) continue;
      if (i == 1)
        dp[j][1] = arr[j];
      else
        dp[j][i] = dp[j][i - 1] ^ dp[j + 1][i - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      dp[j][i] = max(dp[j][i], max(dp[j][i - 1], dp[j + 1][i - 1]));
  }
  int q, l, r;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &l, &r);
    int len = r - l + 1;
    printf("%llu\n", dp[l][len]);
  }
  return 0;
}
