//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));
}
}
segtree query(int node, int start, int end, int l, int r)
{
segtree ans;
if(r<start || end<l) return ans; //range of node is completely outside given range
if(l<=start && end<=r) return tree[node]; // range of node is completely inside given range
int mid = (start+end)/2; //range of node is partially inside and partially outside the given range
segtree p1 = query(2*node, start, mid, l, r);
segtree p2 = query(2*node+1, mid+1, end, l, r);
merge(p1.elems.begin(), p1.elems.end(), p2.elems.begin(), p2.elems.end(), back_inserter(ans.elems));
return ans;
}
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;
}
segtree ans = query(1,1,n,i,j);
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);
cin.tie(0);
cout.tie(0);
int t=1;
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