{-# LANGUAGE FlexibleContexts #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import Data.Ord
import Data.Foldable
import Data.Function
import Debug.Trace

main :: IO ()
main = readLn >>= readContents . pred >>= printRes . solve 
    where
        printRes = mapM_ print

solve :: [[Int]] -> [Int]
solve uvws = map snd . sortOn fst . ((0, 0) :) . concat $ search 0 0 0 vs
    where
        n = 1 + length uvws

        vs = M.fromList . map (\g -> (fst $ head g, map snd g)) . groupBy ((==) `on` fst) . sortOn fst $ concatMap mf uvws
            where
                mf [u, v, w] = [(u - 1, (v - 1, even w)), (v - 1, (u - 1, even w))]

        
        search p i v g = cs : concatMap nf cs
            where
                cs = traceShowId . map mf . filter (\(j, _) -> j /= p) $ g M.! i
                mf (j, b)
                    | b = (j, v)
                    | otherwise = (j, 1 - v)

                nf (j, v) = search i j v g 

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine