#include<bits/stdc++.h>
using namespace std;
const int Nmax=30000+5;
int n,q,a,b,c;
int arr[Nmax];
vector<int>tree[5*Nmax];
void build(int node,int start,int end){
if(start==end){
tree[node].push_back(arr[start]);
return;
}
int mid=start+(end-start)/2;
build(node*2+1,start,mid);
build(node*2+2,mid+1,end);
merge(tree[node*2+1].begin(),tree[node*2+1].end(),tree[node*2+2].begin(),tree[node*2+2].end(),back_inserter(tree[node]));
}
int query(int node,int start,int end,int l,int r,int v){
if(l>end||r<start)
return 0;
if(start>=l&&end<=r){
int k=upper_bound(tree[node].begin(),tree[node].end(),v)-tree[node].begin();
return (end-start+1)-k;
}
int mid=start+(end-start)/2;
return query(node*2+1,start,mid,l,r,v)+query(node*2+2,mid+1,end,l,r,v);
}
int main(){
cin>>n;
for(int i=0;i<n;i++)
cin>>arr[i];
build(0,0,n-1);
cin>>q;
int ans=0;
while(q--){
cin>>a>>b>>c;
int i,j,k;
i=ans^a;
j=ans^b;
k=ans^c;
if(i<1)
i=1;
if(j>n)
j=n;
if(i>j){
ans=0;
cout<<ans<<endl;
continue;
}
i--;
j--;
ans=query(0,0,n-1,i,j,k);
cout<<ans<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE5tYXg9MzAwMDArNTsKaW50IG4scSxhLGIsYzsKaW50IGFycltObWF4XTsKCnZlY3RvcjxpbnQ+dHJlZVs1Kk5tYXhdOwoKdm9pZCBidWlsZChpbnQgbm9kZSxpbnQgc3RhcnQsaW50IGVuZCl7CiAgICBpZihzdGFydD09ZW5kKXsKICAgICAgICB0cmVlW25vZGVdLnB1c2hfYmFjayhhcnJbc3RhcnRdKTsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBpbnQgbWlkPXN0YXJ0KyhlbmQtc3RhcnQpLzI7CiAgICBidWlsZChub2RlKjIrMSxzdGFydCxtaWQpOwogICAgYnVpbGQobm9kZSoyKzIsbWlkKzEsZW5kKTsKICAgIG1lcmdlKHRyZWVbbm9kZSoyKzFdLmJlZ2luKCksdHJlZVtub2RlKjIrMV0uZW5kKCksdHJlZVtub2RlKjIrMl0uYmVnaW4oKSx0cmVlW25vZGUqMisyXS5lbmQoKSxiYWNrX2luc2VydGVyKHRyZWVbbm9kZV0pKTsKfQoKaW50IHF1ZXJ5KGludCBub2RlLGludCBzdGFydCxpbnQgZW5kLGludCBsLGludCByLGludCB2KXsKICAgIGlmKGw+ZW5kfHxyPHN0YXJ0KQogICAgICAgIHJldHVybiAwOwogICAgaWYoc3RhcnQ+PWwmJmVuZDw9cil7CiAgICAgICAgaW50IGs9dXBwZXJfYm91bmQodHJlZVtub2RlXS5iZWdpbigpLHRyZWVbbm9kZV0uZW5kKCksdiktdHJlZVtub2RlXS5iZWdpbigpOwogICAgICAgIHJldHVybiAoZW5kLXN0YXJ0KzEpLWs7CiAgICB9CiAgICBpbnQgbWlkPXN0YXJ0KyhlbmQtc3RhcnQpLzI7CiAgICByZXR1cm4gcXVlcnkobm9kZSoyKzEsc3RhcnQsbWlkLGwscix2KStxdWVyeShub2RlKjIrMixtaWQrMSxlbmQsbCxyLHYpOwp9CgppbnQgbWFpbigpewogICAgY2luPj5uOwogICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgICBjaW4+PmFycltpXTsKICAgIGJ1aWxkKDAsMCxuLTEpOwogICAgY2luPj5xOwogICAgaW50IGFucz0wOwogICAgd2hpbGUocS0tKXsKICAgICAgICBjaW4+PmE+PmI+PmM7CiAgICAgICAgaW50IGksaixrOwogICAgICAgIGk9YW5zXmE7CiAgICAgICAgaj1hbnNeYjsKICAgICAgICBrPWFuc15jOwogICAgICAgIGlmKGk8MSkKICAgICAgICAgICAgaT0xOwogICAgICAgIGlmKGo+bikKICAgICAgICAgICAgaj1uOwogICAgICAgIGlmKGk+ail7CiAgICAgICAgICAgIGFucz0wOwogICAgICAgICAgICBjb3V0PDxhbnM8PGVuZGw7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpLS07CiAgICAgICAgai0tOwogICAgICAgIGFucz1xdWVyeSgwLDAsbi0xLGksaixrKTsKICAgICAgICBjb3V0PDxhbnM8PGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==