#encoding : utf-8

require 'complex'

# Complex * Complex -> Double

def dot(c1, c2)
  (c1.conj * c2).real
end

# Complex * Complex -> Double
def cross(c1, c2)
  (c1.conj * c2).imag
end

# Complex * Complex * Complex -> Complex
# return the proj of vector p0p to vector p0p1
def proj(p0, p1, p)
  (p1 - p0) * dot(p1 - p0, p - p0) / ((p1 - p0).abs ** 2) + p0
end


def sign d
  eps = 1e-8
  d < -eps ? -1 : (d > eps ? 1 : 0)
end

# Complex * Complex * Complex -> Bool
# Return true if Point q is on segment p1p2
# otherwise return false
def on_seg(p1, p2, q)
  sign(cross(p1 - q, p2 - q)) == 0 &&
    sign(dot(p1 - q, p2 - q)) <= 0
end

def direct(p0, p1, p2)
  d = cross(p1 - p0, p2 - p0)
  if sign(d) == 1
    :COUNTER_CLOCKWISE
  elsif sign(d) == -1
    :CLOCKWISE
  else
    if on_seg(p2, p1, p0)
      :ONLINE_BACK
    elsif on_seg(p0, p2, p1)
      :ONLINE_FRONT
    else
      :ON_SEGMENT
    end
  end
end

# Complex * Complex * Complex * Complex -> :PARALL | :OVERLAP | Complex
# Compute the intersect point of two line p0p1 p2p3
# Return:
#       :PARALLEL if two line parallel
#       :OVERLAP if two line overlap
#       Point of the intersection
def intersect_line(p0, p1, p2, p3)
  v1 = Complex(p1 - p0)
  v2 = Complex(p3 - p2)
  if sign(cross(v1, v2)) == 0 and sign(cross(p2 - p0, p2 - p1)) == 0
    :OVERLAP
  elsif sign(cross(v1, v2)) == 0 and sign(cross(p2 - p0, p2 - p1)) != 0
    :PARALLEL
  else
    p2 + (p3 - p2) * ((cross(p1 - p0, p2 - p0)) /
      (cross(p3 - p0, p1 - p0) + cross(p1 - p0, p2 - p0)))
  end
end

def main
  t = gets.chomp.to_i
  (1..t).each do |ca|
    x1, y1, x2, y2, x3, y3, x4, y4 = gets.chomp.split(/\s/).collect {|x| x.to_f}
    p0, p1 = Complex(x1, y1), Complex(x2, y2)
    p2, p3 = Complex(x3, y3), Complex(x4, y4)
    int = intersect_line(p0, p1, p2, p3)
    if int == :OVERLAP or int == :PARALLEL
      puts "0"
    elsif on_seg(p0, p1, int) and on_seg(p2, p3, int)
      puts "1"
    else
      puts "0"
    end
  end
end

main