mod = 10**9+7 n, k, x = map(int,input().split()) def f(): m = n-2 low = 1 high = 0 for i in range(m): low,high = high*(k-1)%mod,low+high*(k-2)%mod if x == 1: return high*(k-1) else: return high*(k-2) + low print(f()%mod)