vector<vector<int>> combinations(int n, int mod) {
auto res = vector<vector<int>>(n + 1, vector<int>(n + 1));
rep(i, n + 1) res[i][0] = 1;
for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j)
res[i][j] = (res[i - 1][j - 1] + res[i - 1][j]) % mod;
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int N;
cin >> N;
auto C = combinations(N, 2);
vi A(N);
rep(a, N)cin >> A[a];
vector<vi> X(N, vi(N));
for (int a = 1; a <= N; ++a) {
vi Y;
rep(b, a) {
if (C[a - 1][b])Y.push_back(b);
}
for (int l = 0; l + a <= N; ++l) {
int r = l + a;
int x = 0;
each(y, Y) {
x ^= A[l + y];
}
X[l][r - 1] = x;
}
}
for (int len = 1; len <= N; ++len) {
for (int l = 0; l + len <= N; ++l) {
int r = l + len - 1;
if (l > 0)smax(X[l - 1][r], X[l][r]);
if (r < N - 1)smax(X[l][r + 1], X[l][r]);
}
}
int Q;
cin >> Q;
rep(q, Q) {
int l, r;
cin >> l >> r;
cout << X[l - 1][r - 1] << endl;
}
}