/s { /j exch def j 0 eq { p p } { /w j sqrt cvi def /q w w 2 mod add def /i j q 1 sub dup mul sub def /x q neg 2 idiv def /y x 1 add i q mod add def x y i q idiv { exch neg } repeat p add exch p add exch } ifelse } def { (%stdin) (r) file 99 string readline not { exit } if cvi /n exch def (%stdin) (r) file 99 string readline not { exit } if /z exch def /w z length 1 sub def /p w 2 idiv def /m [ z w { (%stdin) (r) file 99 string readline not { exit } if } repeat ] def n { /b m p get p get def 1 1 w 1 add dup mul 1 sub { /v exch def v s m exch get exch get v 1 sub s m exch get exch 3 2 roll put } for m 0 get 0 b put } repeat m {=} forall (%stdin) (r) file 99 string readline not { exit } if pop (\n) print } loop pop