#include<stdio.h>/*
                     @a=@ARGV;($w,$h)=$a[0]>2&&$a[#*/
                  #define/**/i(w,W,v)if(W){w;}else{v;}/*
               1]>2?@a:(64,64);$o="P1\n$w $h\n"."0\n"x($w-1
             );foreach$y(3..$h){$o.="0 0\n".join"\n",map{rand
            ()>$y/$h?0:1}(3..$w);}print$o,"0\n"x($w+1);$w=q{{*/
          static unsigned char/*}*/o[1024];char*O=(char*)o,*s[]={
         "P7\40WIDTH\40%d\40HEIGHT\40%d","P%d\40%d\40%d","\x89PNG"
         "\r\n\32\n","\xff\xd8","GIF89a","%d %d\n","%d\40%d\40%s\n",
        "GIF87a"};int(M),X,x,K,a,N,n,A;FILE   *f;void J(){a=EOF;i(a=o
       [X++],X<M||((M=fread(o,1,1024,f ))&&     !(X=0)),;)}int/**/P(int
      p,char*q){return*q&&p<M?O[p]==*  q&&P      (p+1,q+1):1;}void Q(){
     #define/*{2013}*/j do{J();if(a==  EOF        ){;return;}}while(0);
     K=X=M=N=0;j;i(K=(o[7]<<8)|o[06]   ;N=         (o[9]<<8)|o[8],M>9&&
   (P(0,s[7])||P(0,s[4])),i(for(X=2    ;;           ){for(a=0;a-255;)j;j
  i(for(n=7;n>0;n>>=1)j;j;n=a<<8;j    n=             a|n ;j;A=a<<8;j;N=n;
 K=A|a;return,a>191&&a<208&&a-196,    ;)              j;  n=(a<<8);j;n=a|
n; for(n-=2;n>0;n--)j},P(0,s[3])      ,                i   (K=(o[16]<<24)
   | (o[17]<<16)|o[19]|(o[18]<<      8                     );N=((o[20]<<
     24)|(o[22]<<8))|(o[21]<<                        16)|o  [23],M>23 &&
    P(0,s[2]),i(for(X=2;X<M   ;X++)i(              ;,o[  X] -35/***//*X
    */,for(;X<M&&o[X]-10;X  ++)o[  X               ]=32;o [  /********/X
    ]=32;)o[1023]=0;i(i(K= N=0,sscanf              (O,s[1    /*****/]/*
    */,&X,&K,&N )-3,;),o[1   ]-55,i(                K=N=    0,/***/+2!=
     sscanf(O,*  s,&K,&N),    ;)),o                         [0]==80&& o
      [1]>=49&&o  [1]<56,;                                  ))))}int
       main(int(p),char**q)                                {;i(;for(
           x  =1;x<p;x++){i(Q                              ();fclose
                 (f),(f=fopen(q                           [(x)],"rb"
                     )),;)printf          (s[0+         +6],K,N,q[
                         x]);},p>                    1,f=stdin;
                           Q();  printf          (s[5    ],K,
                            N))         return!"         }";
                             }