#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_set tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
const ld eps = 1e-9;
const int mod = 1000000007;
const ll inf = 1e18;
const int N1 = 2e5 + 10;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count());
// auto start = chrono::high_resolution_clock::now();
// code here. dont use mbinpow,binpow,right, fact and isprime as function names
// (1/b)%M is (b^(M-2))%M
ll n;
cin>>n;
vector<ll> v(n);
for (ll i = 0; i < n;i++){
cin >> v[i];
}
vector<vector<ll>> dp(n, vector<ll>(n, 0));
vector<vector<ll>> mx(n, vector<ll>(n, 0));
for (ll i = 0; i < n;i++){
dp[i][i] = v[i];
mx[i][i] = v[i];
}
for (ll len = 1; len < n;len++){
for (ll i = 0; i < n - len;i++){
ll j = i + len;
dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j];
mx[i][j] = max(dp[i][j], max(mx[i][j - 1], mx[i + 1][j]));
}
}
ll q;
cin >> q;
while(q--){
ll l, r;
cin >> l >> r;
l--, r--;
cout << mx[l][r] << '\n';
}
}
1644A - Doors and Keys | 1644B - Anti-Fibonacci Permutation |
1610A - Anti Light's Cell Guessing | 349B - Color the Fence |
144A - Arrival of the General | 1106A - Lunar New Year and Cross Counting |
58A - Chat room | 230A - Dragons |
200B - Drinks | 13A - Numbers |
129A - Cookies | 1367B - Even Array |
136A - Presents | 1450A - Avoid Trygub |
327A - Flipping Game | 411A - Password Check |
1520C - Not Adjacent Matrix | 1538B - Friends and Candies |
580A - Kefa and First Steps | 1038B - Non-Coprime Partition |
43A - Football | 50A - Domino piling |
479A - Expression | 1480A - Yet Another String Game |
1216C - White Sheet | 1648A - Weird Sum |
427A - Police Recruits | 535A - Tavas and Nafas |
581A - Vasya the Hipster | 1537B - Bad Boy |