#include <bits/stdc++.h>
int min(int a, int b) { return a > b ? b : a; }
int max(int a, int b) { return a < b ? b : a; }
void swap(int* a, int* b) { *a = *a + *b - (*b = *a); }
int a[5010];
int ans;
int F[5010][5010];
int maxs[5010][5010];
int l[100001];
int r[100001];
int main() {
  int i, j, k;
  int n;
  int q;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    F[i][i] = a[i];
    maxs[i][i] = a[i];
  }
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d", &l[i]);
    scanf("%d", &r[i]);
  }
  for (i = 2; i <= n; i++)
    for (j = i - 1; j >= 1; --j) {
      F[j][i] = F[j + 1][i] ^ F[j][i - 1];
    }
  for (i = 2; i <= n; i++)
    for (j = i - 1; j >= 1; --j) {
      int max2 = max(maxs[j][i - 1], maxs[j + 1][i]);
      maxs[j][i] = max(max2, F[j][i]);
    }
  for (i = 1; i <= q; i++) {
    printf("%d\n", maxs[l[i]][r[i]]);
  }
}
