gets.to_i.times do
  p0, p1, p2, p3 = gets.split.map(&:to_i).each_slice(2).map {|a, b| a + b * 1i }
  u, v, w, z = p1 - p0, p3 - p2, p2 - p0, p3 - p0
  d, c = (u.conj * v).rect
  if c.zero?
    if (u.conj * w).imag.zero?
      ud, wd, zd = [u, w, z].map {|x| (u.conj * x).real }
      a, b = 0, ud
      a, b = b, a if b < a
      p wd < a && zd < a || wd > b && zd > b ? 0 : 1
    else
      p 0
    end
  else
    # t, s are such that p0 + t * u = p2 + s * v
    t = (Complex(*v.rect.reverse!) * w).real.to_f / c
    s = (Complex(*u.rect.reverse!) * w).real.to_f / c
    p 0 <= t && t <= 1 && 0 <= s && s <= 1 ? 1 : 0
  end
end