{$APPTYPE CONSOLE}
{$Q+,R+,O-}

uses SysUtils, Math;

const	debug = 0;
	fName = 'towers';
	maxK = 9;
	maxN = 50000;
	inf = 1E1000;
	maxDeg = 4000;

type TT = record
	k: integer;
	d: array[ 0 .. maxK ] of integer;
end;	

procedure print( var t: TT );

	var i: integer;

	begin
		with t do begin
			write( k, ' ' );
			for i := 0 to k do write( ' ', d[i] );
		end;	
	end;

function count( var t: TT; p: integer ): extended;

	var	i: integer;

	begin
		with t do begin
			assert( p <= k );
			result := d[k];
			for i := k - 1 downto p do begin
				if ( result * log10( d[i] ) > maxDeg ) then begin
					result := inf; exit;
				end;	
				result := power( d[i], result );
			end;	
		end;
	end;

function greater( var s, t: TT; m1, m2: extended; p: integer ): boolean;

	var	sv, tv: extended;

	begin
		if ( debug >= 2 ) then begin
			writeln( ' ', p );
		end;
		sv := m1 * count( s, p );
		tv := m2 * count( t, p );
		if ( sv < inf ) or ( tv < inf ) then
			greater := sv > tv
		else greater := greater( s, t, log10( s.d[p] ), log10( t.d[p] ), p + 1 );	
	end;

var	a: array[ 1 .. maxN ] of TT;
	b, p: array[ 1 .. maxN ] of integer;

procedure qsort( l, r: integer );

	var	i, j, t: integer;
		x: TT;

	begin
		if ( l >= r ) then exit;
		i := l; j := r; x := a[b[( i + j ) shr 1]];
		repeat
			while ( greater( x, a[b[i]], 1, 1, 0 ) ) do inc( i );
			while ( greater( a[b[j]], x, 1, 1, 0 ) ) do dec( j );
			if ( i <= j ) then begin
				t := b[i]; b[i] := b[j]; b[j] :=t;
				inc( i ); dec( j );
			end;
		until ( i > j );
		if ( debug >= 1 ) then begin
			writeln( l, ' ', r );
			print( x ); writeln; writeln;
			for t := l to r do begin
				print( a[t] ); writeln;
			end;
			writeln( i, ' ', j ); writeln;
		end;
		qsort( l, j ); qsort( i, r );	
	end;

var n, i, j: integer;

begin
	reset( input, fName + '.in' );
	rewrite( output, fName + '.out' );
	read( n );
	for i := 1 to n do with a[i] do begin
		read( k );
		for j := 0 to k do read( d[j] );
		b[i] := i;
	end;
	qsort( 1, n );
	for i := 1 to n do p[b[i]] := i;
	for i := 1 to n do write( p[i], ' ' );
	writeln;
end.