#!/bin/python3 import sys def countArray(n, k, x): m = 10**9+7 c = pow(k-1, n-3, m) return (c+1) % m if __name__ == "__main__": n, k, x = input().strip().split(' ') n, k, x = [int(n), int(k), int(x)] answer = countArray(n, k, x) print(answer)