unittest
{
	assert( [ "6", "khabarovsk 20", "moscow 10", "kazan 50", "kazan 35", "moscow 60", "khabarovsk 40" ].parse.expand.solve == "3\n4\n6\n1\n5\n2" );
	assert( [ "10", "yakutsk 10", "yakutsk 20", "yakutsk 30", "yakutsk 40", "yakutsk 50", "yakutsk 60", "yakutsk 70", "yakutsk 80", "yakutsk 90", "yakutsk 100" ].parse.expand.solve == "10\n9\n8\n7\n6\n5\n4\n3\n2\n1" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto spis = new Tuple!( string, long, long )[]( n );
	foreach( i, ref spi; spis )
	{
		input.popFront;
		auto ts = input.front.split;
		spi = tuple( ts[ 0 ], ts[ 1 ].to!( long ), i + 1 );
	}
	return tuple( spis );
}

auto solve( Tuple!( string, long, long )[] spis )
{
	spis.multiSort!( ( a, b ) => a[ 0 ] < b[ 0 ], ( a, b ) => b[ 1 ] < a[ 1 ] );
	return spis.map!( ( a ) => a[ 2 ].to!( string ) ).join( "\n" );
}
