import Control.Monad (replicateM,when,forM_)
import Control.Monad.ST (ST)
import Data.Array.Unboxed (UArray,elems)
import qualified Data.Array.ST as STArr

type Test = ((Int,Int,Int),Bool)
type Checks = UArray Int Int

main = do
    [a,b,c] <- getLine >>= (return . map read . words)
    n <- readLn
    ts <- replicateM n (getLine >>= return . test . map read . words)
    forM_ (elems $ checks (a+b+c) ts) print

    where
    test [a,b,c,1] = ((a,b,c),True)
    test [a,b,c,0] = ((a,b,c),False)

checks :: Int -> [Test] -> Checks
checks m ts = STArr.runSTUArray $ do
    chks <- init m
    forM_ (map fst $ filter snd ts) (applyCollect chks)
    forM_ (map fst $ filter (not . snd) ts) (applyWrong chks)
    return chks

    where
    init m = STArr.newArray (1,m) 2

    applyCollect chks (a,b,c) = do
        STArr.writeArray chks a 1
        STArr.writeArray chks b 1
        STArr.writeArray chks c 1

    applyWrong chks (a,b,c) = do
        ca <- STArr.readArray chks a
        cb <- STArr.readArray chks b
        cc <- STArr.readArray chks c
        when ((ca,cb,cc) == (2,1,1)) (STArr.writeArray chks a 0)
        when ((ca,cb,cc) == (1,2,1)) (STArr.writeArray chks b 0)
        when ((ca,cb,cc) == (1,1,2)) (STArr.writeArray chks c 0)