#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct Student{ string code; int total; Student(string s,int t):code(s),total(t){} }; bool cmp(Student a, Student b){ return a.total>b.total; } int main() { int N,M,G; vector<Student> list; vector<Student>::iterator it; int standard[11]; while(scanf("%d%d%d",&N,&M,&G)!=EOF){ if(N==0){break;} for(int i=1;i<=M;i++){ scanf("%d",&standard[i]); } string s; int exams; int count=0; for(int i=1;i<=N;i++){ int totalScore=0; cin>>s>>exams; while(exams--){ int num; scanf("%d",&num); totalScore+=standard[num]; } list.push_back(Student(s,totalScore)); if(totalScore>=G){ count++; } } sort(list.begin(),list.end(), cmp); printf("%d\n",count); for(it=list.begin();it!=list.end()&&count;it++){ cout<<it->code<<" "<<it->total<<endl; count--; } } return 0; } // 64 位输出请用 printf("%lld")