program line;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var i,j,k,l,m,n,k1,k2:longint;
begin
   reset(input,'line.in');
   read(n);
   for i:=1 to n do
   begin
      read(k);
      k:=k-1;
      k1:=720;
      k2:=715;
      while k>0 do
      begin
         if k1<k2 then k2:=k2-10 else k1:=k1-10;
         dec(k);
      end;
      if (k1>=10)or(k2>=10) then
      begin
         k1:=720-k1;
         k2:=720-k2;
         if k1<k2 then m:=k1 else m:=k2;
         writeln( m div 60,' ', m mod 60);
      end else writeln('NO');
   end;

end.
