-- https://en.wikipedia.org/wiki/Zeller%27s_congruence
zeller :: Int -> Int -> Int -> Int
zeller d m y
  | m == 1 || m == 2 = zeller' d (m + 12) (y - 1)
  | otherwise        = zeller' d m y
  where
      zeller' q m y = let k = y `mod` 100
                          j = y `quot` 100
                      in  (q + (13 * (m + 1) `quot` 5) + k + (k `quot` 4) + (j `quot` 4) + 5 * j) `mod` 7

day :: [String]
day = [ "Saturday"
      , "Sunday"
      , "Monday"
      , "Tuesday"
      , "Wednesday"
      , "Thursday"
      , "Friday"
      ]

main :: IO ()
main = getContents >>= mapM_ (putStrLn . solve) . init . lines
  where solve l = let m:d:_ = map read (words l) in day !! zeller d m 2004