#! /usr/bin/env python N, K, X = [int(token) for token in raw_input().strip().split()] curr_val = 0 if X == 1 else 1 mod = 1000000007 def pow_mod(x, y): number = 1 while y: if y & 1: number = number * x % mod y >>= 1 x = x * x % mod return number for n in range(3, N + 1): curr_val = pow_mod(K - 1, n - 2) - curr_val curr_val %= mod print curr_val