import Control.Monad as M main :: IO () main = do q <- readLn putStr . unlines . map show . solves =<< M.replicateM q readLn solves:: [Int] -> [Int] solves = map solve where solve :: Int -> Int solve 1 = 0 solve 2 = 0 solve 3 = 0 solve 4 = 1 solve n = solve' n 5 (0, 0, 0, 1) solve' :: Int -> Int -> (Int, Int, Int, Int) -> Int solve' n i (a, b, c, d) | n == i = s | otherwise = solve' n (i + 1) (b, c, d, s) where s = (a + b + c + d) `mod` 17