p = 10**9+7 A,B,C = map(int,raw_input().split("^")) print pow(pow(A,B,p),C,p), pow(A,pow(B,C,p-1),p)