{$O-,Q+,R+}
uses SysUtils, Math;

const MaxK=9;
      inf=1e239;
      inf2=1e100;
      eps=1e-6;
      MaxN=50000;
      MaxA=99;

procedure readr (var x:integer; a, b:integer);
begin
  assert (not seekeoln); read (x); assert ((a<=x) and (x<=b));
end;

procedure readl;
begin
  assert (eoln); assert (not eof); readln
end;

type ip=record
       l, o:integer;
       x:extended;
     end;
     tow=array [0..MaxK] of integer;


         
function pseudoeval (s, k:integer; const t:tow):extended;
var i:integer;
begin
  assert (s<=k);
  Result:=t[k];
  for i:=k-1 downto s do begin
    if t[i]=1 then Result:=1 else
    if Result>1000 then Result:=inf else begin
      assert (Result=round (Result));
      Result:=IntPower (t[i], round (Result));
      if Result>inf then Result:=inf;
    end;
  end;
end;


procedure convert (k:integer; const t:tow; var r:ip);
begin
  r.l:=0; r.x:=pseudoeval (0, k, t);
  while r.x>=inf2 do begin
    inc (r.l); r.x:=pseudoeval (r.l, k, t)*ln (t[r.l-1]);
  end;
end;

function myln (x:extended):extended;
begin
  if x<=eps then myln:=-inf else myln:=ln (x);
end;


function less (var a, b:ip):boolean;
var l1, l2:extended;
    i:integer;
begin
  if a.o=b.o then begin Result:=false; exit end;
  l1:=a.x; l2:=b.x;
  for i:=a.l+1 to b.l do l1:=myln (l1);
  for i:=b.l+1 to a.l do l2:=myln (l2);
  assert (abs (l1-l2)>eps);
  less:=l1<l2;
end;

var A:array [1..MaxN] of ip;


procedure qsort (l, r:integer);
var i, j:integer;
    x, y:ip;
begin
  if l>=r then exit;
  i:=l; j:=r; x:=A[(l+r) shr 1];
  repeat
    while less (A[i], x) do inc (i);
    while less (x, A[j]) do dec (j);
    if i<=j then begin
      y:=A[i]; A[i]:=A[j]; A[j]:=y;
      inc (i); dec (j)
    end
  until i>j;
  qsort (l, j);
  qsort (i, r);
end;



var tmp:tow;
    i, j, K, N:integer;


begin
  reset (input, 'towers.in');
  rewrite (output, 'towers.out');
  readr (N, 1, MaxN); readl;
  for i:=1 to N do begin
    readr (K, 1, 9);
    for j:=0 to K do readr (tmp[j], 1, MaxA);
    convert (k, tmp, A[i]);
    A[i].o:=i;
    readl;
  end;
  assert (eof);
  qsort (1, N);

  for i:=1 to N-1 do
    assert (less (A[i], A[i+1]) and not less (A[i+1], A[i]));

  for i:=1 to N do write (A[i].o, ' ');
end.