#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int a[n][n];
  int m[n][n];
  for (int i = 0; i < n; ++i) scanf("%d", &a[0][i]), m[0][i] = a[0][i];
  for (int i = 1; i < n; ++i)
    for (int j = 0; j < n - i; ++j)
      a[i][j] = a[i - 1][j] ^ a[i - 1][j + 1],
      m[i][j] =
          ((a[i][j] > ((m[i - 1][j] > m[i - 1][j + 1]) ? (m[i - 1][j])
                                                       : (m[i - 1][j + 1])))
               ? (a[i][j])
               : (((m[i - 1][j] > m[i - 1][j + 1]) ? (m[i - 1][j])
                                                   : (m[i - 1][j + 1]))));
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l, --r;
    printf("%d\n", m[r - l][l]);
  }
}
