//Segment tree approach to Range-sum and update query problem.
//arr and tree are 1-indexed
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define all(a) (a).begin(),(a).end()
#define lol 1000000007
#define endl '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define SIZE 1000005
using namespace std;
void MOD(ll &x)
{
if (x >= lol) x -= lol;
if (x < 0) x += lol;
}
typedef struct segtree
{
vector<ll> elems;
}segtree;
ll arr[SIZE+5];
segtree tree[4*SIZE+5];
int n, q;
void build(int node, int start, int end)
{
if(start>end) return;
if(start==end)
{
tree[node].elems.pb(arr[start]);
}
else
{
int mid = (start+end)/2;
build(2*node, start, mid);
build(2*node+1, mid+1, end);
merge(tree[2*node].elems.begin(), tree[2*node].elems.end(), tree[2*node+1].elems.begin(), tree[2*node+1].elems.end(), back_inserter(tree[node].elems));
}
}
int query(int node, int start, int end, int l, int r, ll k)
{
if(r<start || end<l) return 0;
if(l<=start && end<=r) return (int)(tree[node].elems.size() - (upper_bound(tree[node].elems.begin(), tree[node].elems.end(), k)-tree[node].elems.begin()));
int mid = (start+end)/2;
int p1 = query(2*node, start, mid, l, r, k);
int p2 = query(2*node+1, mid+1, end, l, r, k);
//merge(p1.elems.begin(), p1.elems.end(), p2.elems.begin(), p2.elems.end(), back_inserter(ans.elems));
return p1+p2;
}
void solve()
{
cin>>n;
rep(i,1,n+1) cin>>arr[i];
build(1,1,n);
cin>>q;
int last_ans = 0;
rep(i1,1,q+1)
{
int a, b;
ll c;
cin>>a>>b>>c;
int i = a^last_ans;
int j = b^last_ans;
ll k = c^last_ans;
// if(i<1) i=1;
// if(j>n) j=n;
// if(i>j)
// {
// last_ans = 0;
// cout<<last_ans<<endl;
// continue;
// }
last_ans = query(1,1,n,i,j,k);
//last_ans = (int)(ans.elems.size() - (upper_bound(ans.elems.begin(), ans.elems.end(), k)-ans.elems.begin()));
cout<<last_ans<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
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