modPow a b d = loop 1 a b where loop x r 0 = x loop x r b = loop (if even b then x else (mod (x*r) d)) (mod (r*r) d) (div b 2) dee = 10^9 + 7 ded = 10^9 + 6 main = do li <- getLine let (a:b:c:_) = map read $ words $ map (\c -> if c == '^' then ' ' else c) li let r1 = modPow (modPow a b dee) c dee let r2 = modPow a (modPow b c ded) dee putStrLn (show r1 ++ " " ++ show r2)