#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
#define manx 100009
int x[manx],tree[20][manx],sum_left[20][manx];
void make(int level,int left,int right){
if(left==right) return ;
int mid = (left+right)>>1;
int num = mid - left + 1;
for(int i=left;i<=right;i++){
if(tree[level][i]<x[mid])
num--;
}
int lpos = left, rpos = mid+1;
for(int i=left; i<=right; i++){
if(i==left) sum_left[level][i]=0;
else sum_left[level][i]=sum_left[level][i-1];
if(tree[level][i]<x[mid]){
sum_left[level][i]++;
tree[level+1][lpos++] = tree[level][i];
}
else if(tree[level][i]>x[mid])
tree[level+1][rpos++] = tree[level][i];
else {
if(num > 0){
num--;
sum_left[level][i]++;
tree[level+1][lpos++]=tree[level][i];
}
else tree[level+1][rpos++]=tree[level][i];
}
}
make(level+1,left,mid);
make(level+1,mid+1,right);
}
int query(int level,int left,int right,int l,int r,int k){
if(l==r) return tree[level][l];
int s, ss, mid = (left+right)>>1;
if(left==l){
s = 0;
ss = sum_left[level][r];
}
else {
s = sum_left[level][l-1];
ss = sum_left[level][r]-s;
}
int newl,newr;
if(k<=ss){
newl = left + s;
newr = left + s + ss - 1;
return query(level+1,left,mid,newl,newr,k);
}
else {
newl = mid + (l-left-s+1);
newr = mid + (r-left-s-ss+1);
return query(level+1,mid+1,right,newl,newr,k-ss);
}
}
int main(){
int n,q,ca=0;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
scanf("%d",&tree[0][i]);
x[i] = tree[0][i];
}
sort(x+1,x+n+1);
make(0,1,n);
printf("Case %d:\n",++ca);
while(q--){
int l,r,k;
scanf("%d%d%d",&l,&r,&k);
l++, r++;
int mid,left=1,right=r-l+1,ans=0;;
while(left<=right){
mid = (left+right)>>1;
if(query(0,1,n,l,r,mid)>k) right=mid-1;
else {
ans = mid;
left = mid+1;
}
}
printf("%d\n",ans);
}
}
}