mygcd :: Integral a => a -> a -> a
mygcd a 0 = a
mygcd a b = mygcd b $ mod a b

main :: IO ()
main = putStr . unlines .
    map (\(a : b : _) -> show $ mygcd a b) .
        map (map read) . map words . lines =<< getContents