class Point
  attr_reader :x, :y
  def initialize(x, y)
    @x = x
    @y = y
  end
end
class Line
  attr_reader :p1, :p2, :maxx, :minx, :maxy, :miny, :x, :y
  def initialize(x1, y1, x2, y2)
    @p1 = Point.new(x1, y1)
    @p2 = Point.new(x2, y2)
    @maxx = (x1 > x2)? x1 : x2
    @minx = (x1 > x2)? x2 : x1
    @maxy = (y1 > y2)? y1 : y2
    @miny = (y1 > y2)? y2 : y1
    @x = x1 - x2
    @y = y1 - y2
  end
  def parallel?(other)
    return (x * other.y) == (y * other.x)
  end
  def over_x?(other)
    return (x ** 2 + other.x ** 2 >= (maxx - other.maxx) ** 2 + (minx - other.mixx) ** 2)
  end
  def over_y?(other)
    return (y ** 2 + other.y ** 2 >= (maxy - other.maxy) ** 2 + (miny - other.miny) ** 2)
  end
  def get_xy(other)
    return (y * other + (x * p2.y - y * p2.x))
  end
  def get_yx(other)
    return (x * other + (y * p2.x - x * p2.y))
  end
  def cross_x?(other)
    return (other.x * p1.y - other.get_xy(p1.x)) * (other.x * p2.y - other.get_xy(p2.x)) <= 0
  end
  def cross_y?(other)
    return (other.y * p1.x - other.get_yx(p1.y)) * (other.y * p2.x - other.get_yx(p2.y)) <= 0
  end
  def intersection?(other)
    if (parallel?(other))
      if (x * y == 0)
        if (x == 0)
          return ((p1.x == other.p1.x) and (over_y?(other)))
        else
          return ((p1.y == other.p1.y) and (over_x?(other)))
        end
      else
        return (cross_x?(other) and over_x?(other))
      end
    else
      if (y == 0 or other.y == 0)
        return (cross_x?(other) and other.cross_x?(self))
      else
        return (cross_y?(other) and other.cross_y?(self))
      end
    end
  end
end

def main(input = STDIN, output = nil)
  q = input.gets.to_i
  q.times do |i|
    arg = input.gets.split(" ").map(&:to_i)
    l1 = Line.new(*arg[0...4])
    l2 = Line.new(*arg[4..-1])
    if (l1.intersection?(l2))
      puts "1"
    else
      puts "0"
    end
  end
end
main