input = input() # print(input.split(' ')) A, B, K, C = input.split() if C != A and C != B: print(0) else: print(int(2 ** (int(K)) * int(K) / 2) % 1000000007)