#include <bits/stdc++.h>
using namespace std;
int n;
int a[5001][5001], m, l, r, c;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i][i];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n - i + 1; j++) {
      a[j][i + j - 1] = a[j][j + i - 2] ^ a[j + 1][j + i - 1];
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n - i + 1; j++) {
      a[j][i + j - 1] =
          (a[j][i + j - 1] > (a[j][j + i - 2] > a[j + 1][j + i - 1]
                                  ? a[j][j + i - 2]
                                  : a[j + 1][j + i - 1])
               ? a[j][i + j - 1]
               : (a[j][j + i - 2] > a[j + 1][j + i - 1] ? a[j][j + i - 2]
                                                        : a[j + 1][j + i - 1]));
    }
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r;
    cout << a[l][r] << endl;
  }
}
