import scala.io.StdIn.{readInt,readLine}

object Main {
  def cross(x0:Double, y0:Double, x1:Double, y1:Double) = x0*y1-x1*y0
  def inner(x0:Double, y0:Double, x1:Double, y1:Double) = x0*x1+y0*y1
  def norm(x:Double, y:Double) = x*x+y*y

  def dir(x0:Double,y0:Double,x1:Double,y1:Double) =
    if(cross(x0,y0,x1,y1) > (1e-10)) (-1)
    else if(cross(x0,y0,x1,y1) < -(1e-10)) 1
    else if(inner(x0,y0,x1,y1) < -(1e-10)) 1
    else if(norm(x0,y0) < norm(x1,y1)) 0
    else 0

  def intersect(x0:Double,y0:Double,x1:Double,y1:Double,x2:Double,y2:Double,x3:Double,y3:Double) = {
   (dir(x2-x0,y2-y0,x1-x0,y1-y0) * dir(x3-x0,y3-y0,x1-x0,y1-y0) <= 0) &&
    (dir(x1-x2,y1-y2,x3-x2,y3-y2) * dir(x0-x2,y0-y2,x3-x2,y3-y2) <= 0)
  }

  def main(args:Array[String]) = {
    val n = readInt
    for(i<-0 until n) {
      val s = readLine.split(" ").map(_.toDouble)
      if(intersect(s(0),s(1),s(2),s(3),s(4),s(5),s(6),s(7))) println(1)
      else println(0)
    }
  }
}