#include <bits/stdc++.h>
typedef struct upit {
  int l;
  int r;
} Upit;
int n;
int *a;
int q;
Upit *upiti;
int **opt;
int **xors;
int *pom;
int OdrediMaksimum(int a, int b, int c) {
  if (a >= b) {
    if (a >= c)
      return a;
    else
      return c;
  } else {
    if (b >= c)
      return b;
    else
      return c;
  }
}
int Xor(int d, int g) {
  int i;
  int rez = a[g];
  for (i = g - 1; i > d + 2; i--) {
    rez = rez ^ a[i];
  }
  rez = rez ^ xors[d][g - 1];
  return rez;
}
int main() {
  int i, j;
  scanf("%d", &n);
  a = (int *)malloc((n + 1) * sizeof(int));
  opt = (int **)malloc((n + 1) * sizeof(int *));
  xors = (int **)malloc((n + 1) * sizeof(int *));
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    opt[i] = (int *)malloc((n + 1) * sizeof(int));
    opt[i][i] = a[i];
    xors[i] = (int *)malloc((n + 1) * sizeof(int));
    xors[i][i] = a[i];
  }
  scanf("%d", &q);
  upiti = (Upit *)malloc((q + 1) * sizeof(Upit));
  for (i = 1; i <= q; i++) {
    scanf("%d%d", &upiti[i].l, &upiti[i].r);
  }
  for (i = n - 1; i > 0; i--) {
    for (j = i + 1; j <= n; j++) {
      xors[i][j] = xors[i + 1][j] ^ xors[i][j - 1];
      opt[i][j] = OdrediMaksimum(opt[i][j - 1], opt[i + 1][j], xors[i][j]);
    }
  }
  for (i = 1; i <= q; i++) {
    printf("%d\n", opt[upiti[i].l][upiti[i].r]);
  }
  return 0;
}
