#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long arr[5005];
  int n;
  while (cin >> n) {
    deque<long long> dq;
    static long long dp[5005][5005];
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
      dp[1][i] = arr[i];
      dq.push_back(arr[i]);
    }
    for (int i = 1; i <= n; i++) {
      int cnt = 1;
      for (int j = i + 1; j <= n; j++) {
        long long x = dq.front();
        dq.pop_front();
        long long y = dq.front();
        long long z = (x ^ y);
        dp[i + 1][cnt] = max(z, max(dp[i][cnt], dp[i][cnt + 1]));
        dq.push_back(z);
        cnt++;
      }
      dq.pop_front();
    }
    int q;
    cin >> q;
    for (int i = 1; i <= q; i++) {
      int l, r;
      cin >> l >> r;
      int x = abs(l - r) + 1;
      cout << dp[x][l] << "\n";
    }
  }
  return 0;
}
