#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int arr[5010];
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
//for(int i=0;i<n;i++){
// cout<<arr[i];
//}
int f[5010][5010];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
f[i][j]=0;
}
}
for(int i=0;i<n;i++){
//cout<<i;
//cout<<arr[i];
f[i][i] = arr[i];
//cout<<f[i][i];
}
//cout<<f[1][1];
for(int i=0;i<n-1;i++){
int answ = arr[i];
for(int j=i+1;j<n;j++){
answ = answ ^ arr[j];
if((j-i)%2==0){
f[i][j] = arr[i] ^ arr[j];
}
else{
f[i][j] = answ;
}
}
}
//cout<<f[1][1];
int ans[5010][5010];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
ans[i][j]=0;
}
}
for(int i=0;i<n;i++){
ans[i][i] = arr[i];
}
// cout<<ans[0][0];
int maxrow[5010][5010];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
maxrow[i][j]=0;
}
}
for(int i=0;i<n;i++){
maxrow[i][i] = arr[i];
}
//cout<<ans[0][0];
//cout<<maxrow[0][0];
//cout<<maxrow[0][1];
for(int j=1;j<n;j++){
// cout<<j<<" "<<j<<" ,";
int max = f[j][j];
// cout<<f[j][j];
for(int i=j-1;i>=0;i--){
// cout<<i<<" "<<j<<" ,";
if(f[i][j]>max){
max = f[i][j];
}
maxrow[i][j] = max;
// cout<<maxrow[i][j];
}
}
//cout<<maxrow[0][1];
// cout<<"\n";
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// cout<<f[i][j]<<" ";
// }
// cout<<"\n";
// }
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// cout<<maxrow[i][j]<<" ";
// }
// cout<<"\n";
// }
// cout<<ans[0][0];
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
// cout<<i<<" "<<j<<"\n";
// cout<<i<<" "<<j-1<<"\n";
// cout<<ans[i][j];
//ans[i][j] = max(ans[i][j-1], maxrow[i][j]);
if(ans[i][j-1] > maxrow[i][j]){
ans[i][j] = ans[i][j-1];
}
else{
ans[i][j] = maxrow[i][j];
}
}
}
//ans[0][1] = max(ans[0][0], ans[0][1]);
//cout<<ans[0][1];
int q;
cin>>q;
int x,y;
// cout<<ans[0][0];
// cout<<f[0][0];
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// cout<<ans[i][j]<<" ";
// }
// cout<<"\n";
// }
for(int i=0;i<q;i++){
cin>>x>>y;
// cout<<x<<" "<<y<<endl;
cout<<ans[x-1][y-1]<<endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCkgewogICAgaW50IG47CiAgICBpbnQgYXJyWzUwMTBdOwogICAgY2luPj5uOwogICAgZm9yKGludCBpPTA7aTxuO2krKyl7CiAgICAgICAgY2luPj5hcnJbaV07CiAgICB9CiAgICAvL2ZvcihpbnQgaT0wO2k8bjtpKyspewogICAgLy8gICAgY291dDw8YXJyW2ldOwogICAgLy99CiAgICBpbnQgZls1MDEwXVs1MDEwXTsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICBmb3IoaW50IGo9MDtqPG47aisrKXsKICAgICAgICBmW2ldW2pdPTA7CiAgICAgIH0gICAgCiAgICB9CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICAvL2NvdXQ8PGk7CiAgICAgICAgLy9jb3V0PDxhcnJbaV07CiAgICAgICAgZltpXVtpXSA9IGFycltpXTsKICAgICAgICAvL2NvdXQ8PGZbaV1baV07CiAgICB9CiAgICAvL2NvdXQ8PGZbMV1bMV07CiAgICBmb3IoaW50IGk9MDtpPG4tMTtpKyspewogICAgICAgIGludCBhbnN3ID0gYXJyW2ldOwogICAgICAgIGZvcihpbnQgaj1pKzE7ajxuO2orKyl7CiAgICAgICAgICAgIGFuc3cgPSBhbnN3IF4gYXJyW2pdOwogICAgICAgICAgICBpZigoai1pKSUyPT0wKXsKICAgICAgICAgICAgICAgIGZbaV1bal0gPSBhcnJbaV0gXiBhcnJbal07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIGZbaV1bal0gPSBhbnN3OwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgLy9jb3V0PDxmWzFdWzFdOwogICAgaW50IGFuc1s1MDEwXVs1MDEwXTsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICBmb3IoaW50IGo9MDtqPG47aisrKXsKICAgICAgICBhbnNbaV1bal09MDsKICAgICAgfQogICAgfQogICAgZm9yKGludCBpPTA7aTxuO2krKyl7CiAgICAgICAgYW5zW2ldW2ldID0gYXJyW2ldOwogICAgfQogICAgLy8gY291dDw8YW5zWzBdWzBdOwogICAgaW50IG1heHJvd1s1MDEwXVs1MDEwXTsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICBmb3IoaW50IGo9MDtqPG47aisrKXsKICAgICAgICBtYXhyb3dbaV1bal09MDsKICAgICAgfQogICAgfQogICAgZm9yKGludCBpPTA7aTxuO2krKyl7CiAgICAgICAgbWF4cm93W2ldW2ldID0gYXJyW2ldOwogICAgfQogICAgLy9jb3V0PDxhbnNbMF1bMF07CiAgICAvL2NvdXQ8PG1heHJvd1swXVswXTsKICAgIC8vY291dDw8bWF4cm93WzBdWzFdOwogICAgIGZvcihpbnQgaj0xO2o8bjtqKyspewogICAgICAgICAvLyBjb3V0PDxqPDwiICI8PGo8PCIgLCI7CiAgICAgICAgIGludCBtYXggPSBmW2pdW2pdOwogICAgICAgICAvLyBjb3V0PDxmW2pdW2pdOwogICAgICAgICBmb3IoaW50IGk9ai0xO2k+PTA7aS0tKXsKICAgICAgICAgICAgIC8vIGNvdXQ8PGk8PCIgIjw8ajw8IiAsIjsKICAgICAgICAgICAgIGlmKGZbaV1bal0+bWF4KXsKICAgICAgICAgICAgICAgICBtYXggPSBmW2ldW2pdOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgIG1heHJvd1tpXVtqXSA9IG1heDsKICAgICAgICAgICAgIC8vIGNvdXQ8PG1heHJvd1tpXVtqXTsKICAgICAgICAgfQogICAgIH0KICAgICAvL2NvdXQ8PG1heHJvd1swXVsxXTsKICAgICAvLyBjb3V0PDwiXG4iOwogICAgIC8vIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgIC8vICAgZm9yKGludCBqPTA7ajxuO2orKyl7CiAgICAgLy8gICAgIGNvdXQ8PGZbaV1bal08PCIgIjsKICAgICAvLyAgIH0KICAgICAvLyAgIGNvdXQ8PCJcbiI7CiAgICAgLy8gfQogICAgIC8vIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgIC8vICAgZm9yKGludCBqPTA7ajxuO2orKyl7CiAgICAgLy8gICAgIGNvdXQ8PG1heHJvd1tpXVtqXTw8IiAiOwogICAgIC8vICAgfQogICAgIC8vICAgY291dDw8IlxuIjsKICAgICAvLyB9CiAgICAgLy8gY291dDw8YW5zWzBdWzBdOwogICAgIGZvcihpbnQgaT0wO2k8bi0xO2krKyl7CiAgICAgICAgIGZvcihpbnQgaj1pKzE7ajxuO2orKyl7CiAgICAgICAgICAgICAvLyBjb3V0PDxpPDwiICI8PGo8PCJcbiI7CiAgICAgICAgICAgICAvLyBjb3V0PDxpPDwiICI8PGotMTw8IlxuIjsKICAgICAgICAgICAgIC8vIGNvdXQ8PGFuc1tpXVtqXTsKICAgICAgICAgICAgIC8vYW5zW2ldW2pdID0gbWF4KGFuc1tpXVtqLTFdLCBtYXhyb3dbaV1bal0pOwogICAgICAgICAgICAgaWYoYW5zW2ldW2otMV0gPiBtYXhyb3dbaV1bal0pewogICAgICAgICAgICAgCWFuc1tpXVtqXSA9IGFuc1tpXVtqLTFdOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgIAlhbnNbaV1bal0gPSBtYXhyb3dbaV1bal07CiAgICAgICAgICAgICB9CiAgICAgICAgIH0KICAgICB9CiAgICAgLy9hbnNbMF1bMV0gPSBtYXgoYW5zWzBdWzBdLCBhbnNbMF1bMV0pOwogICAgIC8vY291dDw8YW5zWzBdWzFdOwogICAgIGludCBxOwogICAgIGNpbj4+cTsKICAgICBpbnQgeCx5OwogICAgIC8vIGNvdXQ8PGFuc1swXVswXTsKICAgICAvLyBjb3V0PDxmWzBdWzBdOwogICAgIC8vIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgIC8vICAgZm9yKGludCBqPTA7ajxuO2orKyl7CiAgICAgLy8gICAgIGNvdXQ8PGFuc1tpXVtqXTw8IiAiOwogICAgIC8vICAgfQogICAgIC8vICAgY291dDw8IlxuIjsKICAgICAvLyB9CiAgICAgZm9yKGludCBpPTA7aTxxO2krKyl7CiAgICAgICAgIGNpbj4+eD4+eTsKICAgICAgICAgLy8gY291dDw8eDw8IiAgIjw8eTw8ZW5kbDsKICAgICAgICAgY291dDw8YW5zW3gtMV1beS0xXTw8ZW5kbDsKICAgICB9CiAgICAgcmV0dXJuIDA7Cn0K