#include <bits/stdc++.h>
using namespace std;
int a[5010];
int p[5010];
int d[5010][5010];
int main() {
  cin.tie(0);
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  int prev[5010];
  int prev2[5010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    prev[i] = a[i];
  }
  p[0] = a[0];
  for (int i = 1; i < n; i++) p[i] = p[i - 1] ^ a[i];
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      prev2[j] = prev[j] ^ prev[j + 1];
      d[j][j + i - 1] = prev2[j];
    }
    for (int j = 0; j <= n - i; j++) prev[j] = prev2[j];
  }
  for (int i = 0; i < n; i++) d[i][i] = a[i];
  for (int k = 1; k <= n; k++)
    for (int i = 0; i < n - k; i++) {
      if (i < n) d[i][i + k] = max(d[i][i + k], d[i + 1][i + k]);
      if (i + k - 1 >= 0) d[i][i + k] = max(d[i][i + k], d[i][i + k - 1]);
    }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x1;
    int x2;
    cin >> x1 >> x2;
    x1--;
    x2--;
    cout << d[x1][x2] << "\n";
  }
  return 0;
}
