#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct student
{
char xh[100];
int sum;
}student;
student stu[1010];
int comp(const void*a,const void*b)
{
student *p=(student*)a;
student *q=(student*)b;
if(p->sum!=q->sum)
return q->sum-p->sum; /*注意-号*/
else
return strcmp(p->xh,q->xh);
}
int main()
{
int n,m,g,x,a[20],i,j,y,t;
while(~scanf("%d",&n)&&n)
{
scanf("%d %d",&m,&g);
t=0;
for(i=1;i<=m;i++)
scanf("%d",&a[i]);
for(j=0;j<n;j++)
{
stu[j].sum=0;
scanf("%s %d",stu[j].xh,&x);
while(x--)
{
scanf("%d",&y);
stu[j].sum+=a[y];
}
if(stu[j].sum>=g)
t++;
}
qsort(stu,n,sizeof(struct student),comp);
printf("%d\n",t);
for(i=0;i<t;i++)
{
printf("%s %d\n",stu[i].xh,stu[i].sum);
}
}
return 0;
}
#include<string.h>
#include<stdlib.h>
typedef struct student
{
char xh[100];
int sum;
}student;
student stu[1010];
int comp(const void*a,const void*b)
{
student *p=(student*)a;
student *q=(student*)b;
if(p->sum!=q->sum)
return q->sum-p->sum; /*注意-号*/
else
return strcmp(p->xh,q->xh);
}
int main()
{
int n,m,g,x,a[20],i,j,y,t;
while(~scanf("%d",&n)&&n)
{
scanf("%d %d",&m,&g);
t=0;
for(i=1;i<=m;i++)
scanf("%d",&a[i]);
for(j=0;j<n;j++)
{
stu[j].sum=0;
scanf("%s %d",stu[j].xh,&x);
while(x--)
{
scanf("%d",&y);
stu[j].sum+=a[y];
}
if(stu[j].sum>=g)
t++;
}
qsort(stu,n,sizeof(struct student),comp);
printf("%d\n",t);
for(i=0;i<t;i++)
{
printf("%s %d\n",stu[i].xh,stu[i].sum);
}
}
return 0;
}