import Control.Applicative ((<$>))
import Control.Monad
import Data.Complex
import Data.List ((\\), nub, sort)
import Data.Maybe

type Point = Complex Double
type Vector = Complex Double

eps :: Double
eps = 1e-7

dot :: Vector -> Vector -> Double
dot a b = realPart $ conjugate a * b

cross :: Vector -> Vector -> Double
cross a b = imagPart $ conjugate a * b

normalize :: Vector -> Vector
normalize = signum

readWords :: Read a => IO [a]
readWords = map read . words <$> getLine

data Line = Line {
  a :: Double,
  b :: Double,
  c :: Double
}

data LineSeg = LineSeg {
  p :: Point,
  q :: Point,
  l :: Line
}

mkLine :: Point -> Point -> Line
mkLine p1@(x:+y) p2 = Line a b c where
  (nx:+ny) = (p2-p1)*(0:+1)
  a = nx
  b = ny
  c = -(a*x+b*y)

mkLineSeg :: Point -> Point -> LineSeg
mkLineSeg p1 p2 = LineSeg p1 p2 $ mkLine p1 p2

intersect :: Line -> Line -> Maybe Point
intersect (Line a1 b1 c1) (Line a2 b2 c2)
  | abs ((a1:+b1)`cross`(a2:+b2)) < eps = Nothing
  | otherwise = Just (x/det:+y/det)
  where
    det = a1*b2-b1*a2
    x = c2*b1-c1*b2
    y = a2*c1-a1*c2

intersectLS :: LineSeg -> LineSeg -> Maybe Point
intersectLS (LineSeg p1 q1 l1) (LineSeg p2 q2 l2)
  | cpM == Nothing && online && t1 <= t4 && t3 <= t2 = Just p1
  | cpM == Nothing = Nothing
  | onSeg p1 q1 cp && onSeg p2 q2 cp = Just cp
  | otherwise = Nothing
  where
    cpM = intersect l1 l2
    cp = fromJust cpM
    onSeg p q cp = (cp-p)`dot`(cp-q) < eps
    [t1',t2',t3',t4'] = map (`dot` (normalize (q1-p1))) [p1,q1,p2,q2]
    [t1,t2] = sort [t1',t2']
    [t3,t4] = sort [t3',t4']
    proj p q r = p+((r-p)`dot`d:+0)*d where
      d = normalize (q-p)
    online = magnitude (p2-proj p1 q1 p2) < eps
    
main :: IO ()
main = do
  q <- readLn
  qs <- replicateM q $ do
    [x0,y0,x1,y1,x2,y2,x3,y3] <- readWords :: IO [Double]
    let
      p0 = x0:+y0
      p1 = x1:+y1
      p2 = x2:+y2
      p3 = x3:+y3
    return (p0,p1,p2,p3)

  forM_ qs $ \(p0,p1,p2,p3) -> do
    let cp = intersectLS (mkLineSeg p0 p1) (mkLineSeg p2 p3)

    print $ if cp == Nothing
      then 0
      else 1