program astro;
uses crt;
var unos,ds:string;
    b1,b2,rb1,rb2,rb12,razb:integer;
    i,kG,h,m:integer;

begin
 readln(unos); val(copy(unos,1,2),h,kG);
               val(copy(unos,4,2),m,kG);
               b1:=h*60+m;

 readln(unos); val(copy(unos,1,2),h,kG);
               val(copy(unos,4,2),m,kG);
               b2:=h*60+m;

 readln(unos); val(copy(unos,1,2),h,kG);
               val(copy(unos,4,2),m,kG);
               rb1:=h*60+m;

 readln(unos); val(copy(unos,1,2),h,kG);
               val(copy(unos,4,2),m,kG);
               rb2:=h*60+m;

 if ((b1>b2) and (rb1>rb2)) or ((b2>b1) and (rb2>rb1)) or ((b1=b2) and (rb1=rb2)) or (rb1=rb2) then writeln('nikad') else
 begin
  if b1>b2 then
   while b1<>b2 do begin
      inc(b2,rb2);
      inc(b1,rb1);
      inc(razb,rb2-rb1);
      if razb>=rb2 then begin inc(b2,rb2); inc(razb,-rb2); end;

  end else

   while b1<>b2 do begin
      inc(b2,rb2);
      inc(b1,rb1);
      inc(razb,rb2-rb1);
      if razb>=rb1 then begin inc(b1,rb1); inc(razb,-rb1); end;
   end;

 end;
 writeln(b1,' ',b2)
end.

