main = interact (unlines.map solve.lines)

data Month = Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec deriving (Show, Eq, Ord, Enum)

data Era = Meiji | Taisho | Showa | Heisei deriving (Eq, Ord)

instance Show Era where
        show Meiji = "meiji"
        show Taisho = "taisho"
        show Showa = "showa"
        show Heisei = "heisei"

data DateTime = DT { year :: Int
                   , month :: Month
                   , day :: Int
                   } deriving (Show, Eq)

data Wareki = Wa { era :: Era
                 , waYear :: Int
                 , waMonth :: Month
                 , waDay :: Int
                 }

toDateTime :: Int -> Int -> Int -> DateTime
toDateTime y m d = DT y m' d
    where m' = toEnum (m-1)

instance Ord DateTime where
        compare (DT y1 m1 d1) (DT y2 m2 d2)
            | y1 < y2 = LT
            | y1 > y2 = GT
            | y1 == y2 = case compare m1 m2 of
                             LT -> LT
                             GT -> GT
                             EQ -> compare d1 d2

solve :: String -> String
solve = showWareki.toWareki.(\[y,m,d] -> toDateTime y m d).map read.words

meijiStart = DT 1868 Sep 8
taishoStart = DT 1912 Jul 30
showaStart = DT 1926 Dec 25
heiseiStart = DT 1989 Jan 8

toEra :: DateTime -> Maybe Era
toEra dt
    | dt < meijiStart  = Nothing
    | dt < taishoStart = Just Meiji
    | dt < showaStart  = Just Taisho
    | dt < heiseiStart = Just Showa
    | otherwise        = Just Heisei

toWareki :: DateTime -> Maybe Wareki
toWareki dt
    | dt < meijiStart = Nothing
    | dt < taishoStart = Just (Wa Meiji (year dt - year meijiStart + 1) (month dt) (day dt))
    | dt < showaStart  = Just (Wa Taisho (year dt - year taishoStart + 1) (month dt) (day dt))
    | dt < heiseiStart = Just (Wa Showa (year dt - year showaStart + 1) (month dt) (day dt))
    | otherwise        = Just (Wa Heisei (year dt - year heiseiStart + 1) (month dt) (day dt))

showWareki :: Maybe Wareki -> String
showWareki Nothing = "pre-meiji"
showWareki (Just wa) = unwords.map (\f -> f wa) $ [show.era, show.waYear, show.(+1).fromEnum.waMonth, show.waDay]
