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 = p1 - p0, p3 - p2, p2 - p0
  d, c = (u.conj * v).rect
  # 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 c != 0 && 0 <= t && t <= 1 && 0 <= s && s <= 1 ? 1 : 0
end