/*
TASK: music
LANG: C++
*/
#include <iostream.h>
#define MAXN 10002
using namespace std;
int i, j, k, N, M;

string names[MAXN];
float balls[MAXN];
int nums;
void push(string name, float thebal)
{
	//cout << "push(" << name << ", " << thebal << ")" << endl;
	names[nums] = name;
	balls[nums] = thebal;
	nums++;
}
string pop()
{
	float themax = 0;
	int maxfound = -1;
	string thename = "";
	for (i = 0; i < nums; i++)
	{
		if (balls[i] > themax)
		{
			maxfound = i;
			themax = balls[i];
			thename = names[i];
		}
	}
	for (i = maxfound; i <= nums; i++)
	{
		balls[i] = balls[i+1];
		names[i] = names[i+1];
	}
	nums--;
	//cout << "pop(" << themax << ", " << thename << ")" << endl;
	return thename;
}

float bal;
string name;
int main()
{
	cin >> N;
	for (k = 1; k <= N; k++)
	{
		//cout << "k = " << k << "(N = " << N << ")" << endl;
		cin >> M;
		for (j = 1; j <= M; j++)
		{
			cin >> name >> bal;
			push(name, bal);
		}
		cin >> M;
		for (j = 1; j <= M; j++) pop();
	}
	cout << pop() << endl;
	//system("pause");
	return 0;
}
