/*
TASK:music
LANG:C++
*/
#include <stdio.h>
#include <algo.h>
#include <stdlib.h>
using namespace std;
struct mus{
       char name[12];
       float ball;
       int day;
       int red;
       }com[10001];
int juri[256];
int M[256],Top;
char tmp [2];
int cmp(mus A,mus B)
{
    if(A.ball > B.ball)
    {
              return 0;
    }
    else if(A.ball == B.ball)
    {
         if(A.day > B.day)
         {
                  return 0;
         }
         if(A.day == B.day)
         {
                  if(A.red > B.red)
                  {
                           return 1;
                  }
                  else return 0;
         }
         else return 1;
    }
    else return 1;
}
void GetJuri(int aaa)
{
     sort(com,com+Top,cmp);
     Top-=aaa;
}
int main()
{
      int N,i,j,o;
      scanf("%d",&N);
      for(i = 0;i < N;i++)
      {
             scanf("%d",&M[i]);
             for(j = 0;j < M[i];j++)
             {
                   scanf("%s %f",&com[Top].name,&com[Top].ball);
                   com[Top].day = i;
                   com[Top].red= j;
                   Top++;
             }
             scanf("%d",&juri[i]);
             GetJuri(juri[i]);
      }
      //Momo NEDEI GLEDAAAAAAA
      //Brut Force
      printf("%s\n",com[0].name);
      return 0;
}

