import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  m <- getl toInt
  unless (m == 0) $ do
    xs <- replicateM m (getl $ wrds toInt)
    n <- getl toInt
    unwords . map show . solve m xs <$> replicateM n (getl $ wrds toInt) >>= putStrLn
    main

solve :: Int -> [[Int]] -> [[Int]] -> [Int]
solve m xs ys = maybe [] id $ find f ls
  where
    ls = map (\cs -> zipWith (-) cs (head xs)) ys
    f z = length (intersect (map (zipWith (+) z) xs) ys) == m

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine