a, b, c = map(int, raw_input().split('^')) print pow(pow(a, b, 10**9+7), c, 10**9+7), pow(a, pow(b, c, 10**9+7), 10**9+7)