#include<bits/stdc++.h>
#define mod 1000000007
#define ll int
#define big 100000000000000000
using namespace std;
struct node{
ll sz,*arr;
}st[800010];
ll n,q,a[30000];
void merge(ll a[],ll b[],ll c[],ll sz1,ll sz2,ll sz3){
ll i=0,j=0,k=0;
while(i<sz2 && j<sz3){
if(b[i] < c[j])
a[k++] = b[i++];
else
a[k++] = c[j++];
}
while(i < sz2)
a[k++] = b[i++];
while(j < sz3)
a[k++] = c[j++];
}
ll query(ll in,ll i,ll j,ll l,ll r,ll k){
if(i>j || i>r || j<l)
return 0;
if(i>=l && j<=r){
ll *temp = upper_bound(st[in].arr,st[in].arr+st[in].sz,k);
return st[in].arr+st[in].sz-temp;
}
ll mid = (i+j)/2;
ll temp1 = query(2*in+1,i,mid,l,r,k);
ll temp2 = query(2*in+2,mid+1,j,l,r,k);
return temp1+temp2;
}
void build(ll in=0,ll i=0,ll j=n-1){
if(i>j)
return;
if(i == j){
st[in].sz = 1;
st[in].arr = new int[1];
st[in].arr[0] = a[i];
return;
}
ll mid = (i+j)/2;
build(2*in+1,i,mid);
build(2*in+2,mid+1,j);
st[in].sz = st[2*in+1].sz+st[2*in+2].sz;
st[in].arr = new int[st[in].sz];
merge(st[in].arr,st[2*in+1].arr,st[2*in+2].arr,st[in].sz,st[2*in+1].sz,st[2*in+2].sz);
}
int main(){
// freopen("input.txt","r",stdin);
// ios::sync_with_stdio(0);
ll l,r,i,k,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
build();
/* for(i=0;i<2*n;i++){
cout<<i<<"-";
for(j=0;j<st[i].sz;j++)
cout<<st[i].arr[j]<<" ";
cout<<"\n";
}*/
scanf("%d",&q);
while(q--){
scanf("%d%d%d",&l,&r,&k);
l--;r--;
printf("%d\n",query(0,0,n-1,l,r,k));
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBtb2QgMTAwMDAwMDAwNwojZGVmaW5lIGxsIGludAojZGVmaW5lIGJpZyAxM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