#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  int a[n][n];
  for (int i = 0; i < n; i++) {
    cin >> a[n - 1][i];
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j <= i; j++) {
      a[i][j] = a[i + 1][j] ^ a[i + 1][j + 1];
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j <= i; j++) {
      a[i][j] = max(a[i + 1][j], max(a[i + 1][j + 1], a[i][j]));
    }
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int x, y;
    cin >> x >> y;
    long long int c = n - 1;
    for (;;) {
      if (x == y) {
        break;
      }
      y--;
      c--;
    }
    cout << a[c][x - 1] << "\n";
  }
  return 0;
}
