def hoge(n, k, m): n %= m if k == 0: return 1 if k & 1 == 0: return hoge(n**2 % m, k // 2, m) if k & 1 == 1: return hoge(n**2 % m, k // 2, m) * (n % m) mod = int(1e9+7) a, b, c = map(lambda x : int(x) % mod, input().split('^')) print(hoge(hoge(a, b, mod), c, mod) % mod, hoge(a, hoge(b, c, mod), mod) % mod)