#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1);
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int MAX = 2e5 + 10;
const long long mod = 1e9 + 7;
long long qpow(long long a, long long n) {
  long long re = 1;
  while (n) {
    if (n & 1) re = (re * a) % mod;
    n >>= 1;
    a = (a * a) % mod;
  }
  return re % mod;
}
long long n, k;
long long jie[MAX];
long long inv[MAX];
long long c(long long n, long long m) {
  if (m > n / 2) m = n - m;
  return jie[n] * inv[m] % mod * inv[n - m] % mod;
}
long long f(long long x) {
  long long nhong = qpow(k - 1, x);
  long long hong = qpow(k, n - x) - qpow(k - 1, n - x);
  hong = (hong + mod) % mod;
  return qpow(nhong * hong % mod, n);
}
int main() {
  cin >> n >> k;
  jie[0] = 1;
  for (int i = 1; i <= n; i++) {
    jie[i] = jie[i - 1] * i % mod;
  }
  inv[n] = qpow(jie[n], mod - 2);
  for (int i = n - 1; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
  long long ans = 0;
  for (int i = 0, t = 1; i <= n; i++, t *= -1) {
    ans += c(n, i) * f(i) % mod * t;
    ans %= mod;
  }
  cout << (ans + mod) % mod << '\n';
}
