#include<bits/stdc++.h> usingnamespace std; #ifdef LOCAL #define debug(...) fprintf(stdout, ##__VA_ARGS__) #define debag(...) fprintf(stderr, ##__VA_ARGS__) #else #define debug(...) void(0) #define debag(...) void(0) #endif //#define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back #define fi first #define se second //#define M //#define mo #define N 500010 int n, m, i, j, k, T;
structJi { int p[31], pos[31]; voidinsert(int j, int x){ for(int i = 30, val = x; i >= 0; --i) if(val & (1 << i)) { if(!p[i]) { p[i] = val, pos[i] = j; return ; } if(pos[i] < j) { swap(pos[i], j); swap(val, p[i]); /*continue;*/ } val ^= p[i]; } } intqry(int l){ int ans = 0; // for(int i = 30; i >= 0; --i) // if(p[i]) debug("%d : %d(%d)\n", i, pos[i], p[i]); for(int i = 30; i >= 0; --i) if(p[i] && pos[i] >= l) ans = max(ans, ans ^ p[i]); return ans; } }a[N];
signedmain() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // srand(time(NULL)); // T = read(); // while(T--) { // // } int l, r, x, q, ans; n = read(); for(i = 1; i <= n; ++i) { x = read(); a[i] = a[i - 1]; a[i].insert(i, x); } q = read(); while(q--) { l = read(); r = read(); ans = a[r].qry(l); printf("%d\n", ans); } return0; }