import Control.Monad
import Data.Ratio ((%))

data Line = Vert {pos :: Rational, low :: Rational, high :: Rational} | Line { slope :: Rational
                                                                             , intersect :: Rational
                                                                             , left :: Rational
                                                                             , right :: Rational
                                                                             } deriving Show

main = do
  n <- readLn
  replicateM_ n solve

solve :: IO ()
solve = do
  [x0,y0,x1,y1,x2,y2,x3,y3] <- fmap (map read.words) getLine
  let (l1,l2) = (corrLine (x0,y0) (x1,y1), corrLine (x2,y2) (x3,y3))
  putStrLn $ isCross l1 l2

isCross l1 l2 = if isParallel l1 l2 then "0"
                                    else checkCross l1 l2

checkCross l1 l2
  | isVert l1 = vertCheck l1 l2
  | isVert l2 = vertCheck l2 l1 
  | otherwise = lineCheck l1 l2

vertCheck (Vert x l h) line@(Line sl i s b)
  | highest < s || lowest > h = "0"
  | b < x || s > x = "0"
  | y' >= l && y' <= h = "1"
  | otherwise = "0"
  where highest = getY line s `max` getY line b
        lowest = getY line s `min` getY line b
        y' = getY line x

lineCheck l1 l2
  | left l1 > right l2 || left l2 > right l2 = "0"
  | highl1 < lowl2 || highl2 < lowl2 = "0"
  | otherwise = "1"
  where highl1 = getY l1 (left l1) `max` getY l1 (right l1)
        lowl1  = getY l1 (left l1) `min` getY l1 (right l1)
        highl2 = getY l2 (left l2) `max` getY l2 (right l2)
        lowl2  = getY l2 (left l2) `min` getY l2 (right l2)


getY :: Line -> Rational ->Rational
getY l1 x = slope l1 * x + intersect l1

isVert :: Line -> Bool
isVert (Vert _ _ _) = True
isVert (Line _ _ _ _) = False

isParallel :: Line -> Line -> Bool
isParallel l1 l2
  | isVert l1 = isVert l2
  | isVert l2 = False
  | otherwise = slope l1 == slope l2

isOrthogonal :: Line -> Line -> Bool
isOrthogonal l1 l2
  | isVert l1 && isVert l2 = False
  | isVert l1 = slope l2 == 0
  | isVert l2 = slope l1 == 0
  | otherwise = slope l1 * slope l2 == -1

corrLine :: (Integer,Integer) -> (Integer, Integer) -> Line
corrLine (x1,y1) (x2,y2)
  | x1 == x2 = Vert (x1%1) (min (y1%1) (y2%1)) (max (y1%1) (y2%2))
  | otherwise = Line a b (min (x1%1) (x2%1)) (max (x1%1) (x2%2))
  where a = (y2 - y1) % (x2 - x1)
        b = (y1%1) - a*(x1%1)