
def projector(a, b, c, d, x, y)
  if a * d == b * c
    #p ["a=#{a}","b=#{b}", "c=#{c}", "d=#{d}", x, y]
    if a * y == b * x
      temp = [[x, x - c].sort, [y, y - d].sort]
      if (temp[0][0] < a and 0 < temp[0][1]) or (temp[1][0] < b and 0 < temp[1][1])
        return 0.5, 0.5
      else
        return 2, 2
      end
    else
      return nil, nil
    end
  else
    return ((d * x - b * y) / (a * d - b * c)), ((a * y - x * c) / (a * d - b * c))
  end
end
def main(input = STDIN)
  input.gets.to_i.times do
    points = input.gets.split(" ").map(&:to_r)
    #a1, b1, a2, b2 = *projecter(points[2] - points[0], points[3] - points[1], points[4] - points[0], points[5] - points[1]), *projecter(points[2] - points[0], points[3] - points[1], points[6] - points[0], points[7] - points[1])

    if (a, b = projector(points[2] - points[0], points[3] - points[1], points[6] - points[4], points[7] - points[5], points[6] - points[0], points[7] - points[1])).all?
      #p "not pallarel #{[a, b]}, #{points.map(&:to_f)}"
      if (0 < a and a < 1) and (0 < b and b < 1)
        puts "1"
      else
        puts "0"
      end
    else
      puts "0"
    end
  end
end

main