let () =
  let cross (x0,y0) (x1,y1) = x0*.y1-.x1*.y0 and
      inner (x0,y0) (x1,y1) = x0*.x1+.y0*.y1 and
      norm (x,y) = x*.x+.y*.y in
  let check_lines v1 v0 =
       if cross v0 v1 > (1e-10) then -1
       else if cross v0 v1 < -.(1e-10) then 1
       else if inner v0 v1 < -.(1e-10) then 1
       else if norm v0 < norm v1 then 1
       else 0
  in
  let intersect p0x p0y p1x p1y p2x p2y p3x p3y =
    (check_lines (p2x-.p0x, p2y-.p0y) (p1x-.p0x, p1y-.p0y)) * (check_lines (p3x-.p0x, p3y-.p0y) (p1x-.p0x, p1y-.p0y)) <= 0 &&
      (check_lines (p1x-.p2x, p1y-.p2y) (p3x-.p2x, p3y-.p2y)) * (check_lines (p0x-.p2x, p0y-.p2y) (p3x-.p2x, p3y-.p2y)) <= 0
  in
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  let rec read = function
      0 -> ()
    | i ->
       let (p0x,p0y,p1x,p1y,p2x,p2y,p3x,p3y) =
         Scanf.scanf " %f %f %f %f %f %f %f %f\n" (fun s t u v w x y z -> (s,t,u,v,w,x,y,z))
       in
       if intersect p0x p0y p1x p1y p2x p2y p3x p3y then print_endline "1"
       else print_endline "0"
       ;read (i-1)
  in read n
;;