#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[5005], mxp[5005];
int v[5005][5005], ma[5005][5005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    v[i][1] = ma[i][i] = a[i];
  }
  int b = 1;
  for (int i = 2; i <= n; i++) {
    mxp[i] = b;
    if (b * 2 <= i) b *= 2;
  }
  for (int len = 2; len <= n; len++)
    for (int st = 1; st + len - 1 <= n; st++) {
      int max_pw = mxp[len];
      int x = len - max_pw;
      v[st][len] = v[st][x] ^ v[st + max_pw][x];
      ma[st][st + len - 1] = v[st][len];
    }
  for (int len = 2; len <= n; len++)
    for (int st = 1; st + len - 1 <= n; st++) {
      int &t = ma[st][st + len - 1];
      t = max(t, max(ma[st + 1][st + len - 1], ma[st][st + len - 2]));
    }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", ma[x][y]);
  }
  return 0;
}
