def projecter(x, y, xp, yp)
  return (xp * x + yp * y) / (x ** 2 + y ** 2), (yp * x - xp * y) / (x ** 2 + y ** 2)
end
def check(a1, b1, a2, b2)
  return ((((b2 - b1) * (1 - a1) + b1 * (a2 - a1)) * (b1 * (a2 - a1) - (b2 - b1) * a1) <= 0) and (b1 * b2 <= 0) and subcheck(a1, b1, a2, b2))
end
def subcheck(a1, b1, a2, b2)
  return (b1 != b2 or a1.between?(0,1) or a2.between?(0, 1))
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  check(a1, b1, a2, b2)
      puts "1"
    else
      puts "0"
    end
  end
end
main