Arobothastopatrolaroundarectangularareawhichisinaformofmxngrid(mrowsandncolumns).Therowsarelabeledfrom1tom.Thecolumnsarelabeledfrom1ton.Acell(i,j)denotesthecellinrowiandcolumnjinthegrid.Ateachstep,therobotcanonlymovefromonecelltoanadjacentcell,i.e.from(x,y)to(x+1,y),(x,y+1),(x-1,y)or(x,y-1).Someofthecellsinthegridcontainobstacles.Inordertomovetoacellcontainingobstacle,therobothastoswitchtoturbomode.Therefore,therobotcannotmovecontinuouslytomorethankcellscontainingobstacles.
Yourtaskistowriteaprogramtofindtheshortestpath(withtheminimumnumberofcells)fromcell(1,1)tocell(m,n).Itisassumedthatboththesecellsdonotcontainobstacles.
Theinputconsistsofseveraldatasets.Thefirstlineoftheinputfilecontainsthenumberofdatasetswhichisapositiveintegerandisnotbiggerthan20.Thefollowinglinesdescribethedatasets.
Foreachdataset,ifthereexistsawayfortherobottoreachthecell(m,n),writeinonelinetheintegernumbers,whichisthenumberofmovestherobothastomake;-1otherwise.