gets.to_i.times{eval"L,*A="+$<.take(4).join.split*?, x,y,*g=(0..8).select{|i|A[i]<1} q=->a{A[x]=a A[y]=L-a i=0 0