#! ruby # Try yukicoder # author: Leonardone @ NEETSDKASU ############################################################ def gs() gets.chomp end def gi() gets.to_i end def gf() gets.to_f end def gss() gs.split end def gis() gss.map(&:to_i) end def gfs() gss.map(&:to_f) end def nmapf(n,f) n.times.map{ __send__ f } end def ngs(n) nmapf n,:gs end def ngi(n) nmapf n,:gi end def ngss(n) nmapf n,:gss end def ngis(n) nmapf n,:gis end def arr2d(h,w,v=0) h.times.map{[v] * w} end def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end def nsum(n) n * (n + 1) / 2 end def vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end ############################################################ def isKadomatuRetsu(a1, a2, a3) a1 != a3 && ((a2 > a1 && a2 > a3) || (a2 < a1 && a2 < a3)) end def checkNotKadomatsuRetsu(a1, a2, a3) return true if a1 > 0 && a2 > 0 && a1 == a2 return true if a2 > 0 && a3 > 0 && a2 == a3 return true if a1 > 0 && a3 > 0 && a1 == a3 return a2 != a3 if a1 == 0 return a1 != a3 if a2 == 0 return a1 != a2 if a3 == 0 return isKadomatuRetsu(a1, a2, a3) end t = gi t.times do l = gi a = ngis 3 if checkNotKadomatsuRetsu(a[0][0], a[0][1], a[0][2]) puts 0 next end if checkNotKadomatsuRetsu(a[1][0], a[1][1], a[1][2]) puts 0 next end if checkNotKadomatsuRetsu(a[1][0], a[1][1], a[1][2]) puts 0 next end if checkNotKadomatsuRetsu(a[0][0], a[1][0], a[2][0]) puts 0 next end if checkNotKadomatsuRetsu(a[0][0], a[1][0], a[2][0]) puts 0 next end if checkNotKadomatsuRetsu(a[0][1], a[1][1], a[2][1]) puts 0 next end if checkNotKadomatsuRetsu(a[0][1], a[1][1], a[2][1]) puts 0 next end if checkNotKadomatsuRetsu(a[0][0], a[1][1], a[2][2]) puts 0 next end if checkNotKadomatsuRetsu(a[0][2], a[1][1], a[2][0]) puts 0 next end ans = -1 case 0 when a[0][0] case 0 when a[0][1] when a[0][2] when a[1][0] when a[1][1] when a[1][2] when a[2][0] when a[2][1] when a[2][2] end when a[0][1] case 0 when a[0][2] when a[1][0] when a[1][1] when a[1][2] when a[2][0] when a[2][1] when a[2][2] end when a[0][2] case 0 when a[1][0] when a[1][1] when a[1][2] when a[2][0] when a[2][1] when a[2][2] end when a[1][0] case 0 when a[1][1] when a[1][2] when a[2][0] when a[2][1] when a[2][2] end when a[1][1] case 0 when a[1][2] when a[2][0] when a[2][1] when a[2][2] end when a[1][2] case 0 when a[2][0] when a[2][1] ans = 1 when a[2][2] end when a[2][0] case 0 when a[2][1] when a[2][2] end when a[2][1] case 0 when a[2][2] end end puts ans end