{$A+,B+,D+,E+,F+,G+,I+,L+,N+,O+,P+,Q-,R-,S-,T+,V+,X+,Y+}
{$M 16384,0,655360}
{
TASK:wireless
LANG:Pascal
}
var i,j,n,a,b,c,k,min:longint;
    t:text;
    w:array[1..1000,1..3] of longint;
    s,ss:array[1..1000,1..2] of longint;
    f:array[1..1000] of byte;
    p:array[1..1001] of longint;
procedure check(lev,d:longint);
var i,j,l:longint;
    q:array[1..100] of integer;
begin
if d>=min then exit;
if f[b]*f[c]>0 then
   begin
   min:=d;
   for k:=1 to lev-1 do ss[k]:=s[k];
   exit;
   end;
for i:=1 to n do if f[i]=1 then
    begin
    l:=0;
    f[i]:=2;
    s[lev,1]:=i;
    for j:=p[i]+1 to p[i+1] do if f[w[j,2]]=0 then
        begin
        s[lev,2]:=w[j,3];
        f[w[j,2]]:=1;
        inc(l);
        q[l]:=w[j,2];
        check(lev+1,d+w[j,3]);
        end;
    f[i]:=1;
    for l:=1 to l do f[q[l]]:=0;
    end;
end;
begin
assign(t,'');
reset(t);
readln(t,n,a,b,c);
k:=0;
min:=2000000000;
i:=0;
for n:=1 to n do
    begin
    f[n]:=0;
    read(t,j);
    p[n]:=i;
    for j:=1 to j do
        begin
        inc(i);
        w[i,1]:=n;
        read(t,w[i,2],w[i,3]);
        end;
    end;
p[n+1]:=i;
f[a]:=1;
check(1,0);
writeln(k,' ',min);
for k:=1 to k do writeln(ss[k,1],' ',ss[k,2]);
end.