#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
  return;
}
inline void read(long long &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
  return;
}
int dp[5005][5005];
int arr[5005];
int main() {
  int n;
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(arr[i]);
    dp[i][1] = arr[i];
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[j][i] = dp[j + 1][i - 1] ^ dp[j][i - 1];
    }
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[j][i] = max(dp[j][i], max(dp[j + 1][i - 1], dp[j][i - 1]));
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    read(l);
    read(r);
    printf("%d\n", dp[l][r - l + 1]);
  }
}
