#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;;
const int N=1e5+;
struct T {
int key;
int id;
};
struct ask {
int lr;
int hr;
int val;
int id;
};
T arr[N];
ask q[N];
int tree[N];
int ans [N];
int n,m;
bool cmp1 (T a,T b) {
return a.key<b.key;
}
bool cmp2 (ask a,ask b) {
return a.val<b.val;
}
void add (int x,int k) {
while (k<=n) {
tree[k]+=x;
k+=k&(-k);
}
}
int sum (int k) {
int _ans=;
while (k) {
_ans+=tree[k];
k-=k&(-k);
}
return _ans;
}
int main ()
{
int T;
scanf ("%d",&T);
int num=;
while (T--) {
printf("Case %d:\n",num++);
scanf ("%d %d",&n,&m);
for (int i=;i<=n;i++) {
scanf ("%d",&arr[i].key);
arr[i].id=i;
}
sort (arr+,arr++n,cmp1);
for (int i=;i<=m;i++) {
scanf ("%d %d %d",&q[i].lr,&q[i].hr,&q[i].val);
q[i].id=i;
}
sort (q+,q++m,cmp2);
memset (tree,,sizeof(tree));
int top=;
for (int i=;i<=m;i++) {
while (top<=n&&arr[top].key<=q[i].val) {
add(,arr[top].id);
top++;
}
ans[q[i].id]=sum(q[i].hr+)-sum(q[i].lr);
}
for (int i=;i<=m;i++)
printf("%d\n",ans[i]);
}
return ;
}