#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Person
{
char name[10];
int age,money;
}P[100010];
bool cmp(Person a,Person b)
{
if(a.money!=b.money)
return a.money>b.money;
else if(a.age!=b.age)
return a.age<b.age;
else
return strcmp(a.name,b.name)<0;
}
int main()
{
int N,K;
scanf("%d%d",&N,&K);
for(int i=0 ; i<N ; ++i)
{
scanf("%s %d %d",&P[i].name, &P[i].age, &P[i].money);
}
sort(P,P+N,cmp);
for(int t=1 ; t<=K ; ++t) //查询K次
{
int cnt=0,Qpeople,Qyoung,Qold; //输出记录cnt,输出查询最大人数,最低年龄,最高年龄
scanf("%d%d%d",&Qpeople, &Qyoung, &Qold);
printf("Case #%d:
",t);
for(int i=0 ; i<N ; ++i)
{
if(cnt==Qpeople){ //输出已足够
break;
}
if(P[i].age>=Qyoung && P[i].age<=Qold)
{
printf("%s %d %d
",P[i].name, P[i].age, P[i].money);
++cnt;
}
}
if(0==cnt){
printf("None
");
}
}
return 0;
}