import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    auto B = new long[][](N, N);
    foreach (i; 0..N) B[i][i] = A[i];

    foreach (len; 2..N+1) {
        foreach (l; 0..N-len+1) {
            int r = l + len - 1;
            B[l][r] = B[l+1][r] ^ B[l][r-1];
        }
    }

    auto dp = new long[][](N, N);
    foreach (i; 0..N) dp[i][i] = A[i];

    foreach (len; 2..N+1) {
        foreach (l; 0..N-len+1) {
            int r = l + len - 1;
            dp[l][r] = B[l][r];
            dp[l][r] = max(dp[l][r], dp[l+1][r]);
            dp[l][r] = max(dp[l][r], dp[l][r-1]);
        }
    }

    auto Q = readln.chomp.to!int;
    while (Q--) {
        auto s = readln.split.map!(to!int);
        auto a = s[0] - 1;
        auto b = s[1] - 1;
        dp[a][b].writeln;
    }
}
