{$M 64000,0,640000}
program three_cities;

const
    maxn = 1000;
    
type
    tarr = array [1..maxn] of integer;    
    parr = ^tarr;

var
    n: integer;
    nn: array [1..maxn] of integer;
    nb: array [1..maxn] of parr;
    dp: array [1..maxn] of integer;
    fc: array [1..maxn] of integer;

function search(x, p: integer; var f: integer): integer;
var
    i, j, r, z: integer;
begin
    r := 1;
    f := x;

    for i := 1 to nn[x] do
        if nb[x]^[i] <> p then
        begin
            z := search(nb[x]^[i], x, j) + 1;
            if z > r then
            begin
                r := z;
                f := j;
            end;
        end;
    search := r;
end;

var
    i, j, k, t: integer;
    best, b1, b2, b3: integer;

begin
{    assign(input, 'three.in');
    reset(input);
    assign(output, 'three.out');
    rewrite(output);}

    read(n);
    for i := 1 to n do
    begin
        read(nn[i]);
        getmem(nb[i], sizeof(integer) * nn[i]);
        for j := 1 to nn[i] do
        begin
            read(nb[i]^[j]);
        end;
    end;

    best := 0;
    b1 := 0;
    b2 := 0;
    b3 := 0;
    for i := 1 to n do
        if nn[i] >= 2 then
        begin
            for j := 1 to nn[i] do
            begin
                dp[j] := search(nb[i]^[j], i, fc[j]);
            end;

            if nn[i] = 2 then
            begin
                if dp[1] + dp[2] > best then
                begin
                    b1 := fc[1]; 
                    b2 := fc[2]; 
                    b3 := i; 
                    best := dp[1] + dp[2];
                end;
            end else begin
                for j := 1 to nn[i] do
                    for k := j + 1 to nn[i] do
                    begin
                        if dp[j] < dp[k] then
                        begin
                            t := dp[j];
                            dp[j] := dp[k];
                            dp[k] := t;
                            t := fc[j];
                            fc[j] := fc[k];
                            fc[k] := t;
                        end;
                    end;
                if dp[1] + dp[2] + dp[3] > best then
                begin
                    b1 := fc[1]; 
                    b2 := fc[2]; 
                    b3 := fc[3]; 
                    best := dp[1] + dp[2] + dp[3];
                end;
            end;
        end;

    writeln(b1, ' ', b2, ' ', b3);

    close(input);
    close(output);
end.
