#include <bits/stdc++.h>
using namespace std;
template <typename T1 = int, typename T2 = int, typename T3 = int>
void debug(T1 x, T2 y = T2(), T3 z = T3()) {
  cout << x << " " << y << "  " << z << endl;
}
long long int n, k;
long long int exp(long long int b, long long int p) {
  if (p == 0) return 1;
  long long int temp = exp(b, p / 2);
  long long int ans = temp * temp;
  ans %= (long long int)1e9 + 7;
  if (p & 1) ans *= b;
  ans %= (long long int)1e9 + 7;
  return ans;
}
long long int fac1(long long int p) {
  long long int f = exp(k, p) - exp(k - 1, p);
  f %= (long long int)1e9 + 7;
  while (f < 0) f += (long long int)1e9 + 7;
  return exp(f, n);
}
long long inv(long long a, long long b) {
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n >> k;
  long long int ans = fac1(n);
  vector<long long int> fac(n + 1);
  fac[0] = 1;
  for (long long int i = 1; i <= (long long int)(n); i++)
    fac[i] = fac[i - 1] * i, fac[i] %= (long long int)1e9 + 7;
  long long int sub = 0;
  bool d = true;
  for (long long int i = 1; i <= (long long int)(n - 1); i++) {
    long long int temp = fac1(n - i);
    temp *= exp(k - 1, i * n);
    temp %= (long long int)1e9 + 7;
    temp *= fac[n];
    temp %= (long long int)1e9 + 7;
    temp *= inv(fac[i], (long long int)1e9 + 7);
    temp %= (long long int)1e9 + 7;
    temp *= inv(fac[n - i], (long long int)1e9 + 7);
    temp %= (long long int)1e9 + 7;
    if (d)
      sub += temp;
    else
      sub -= temp;
    d = !d;
    sub %= (long long int)1e9 + 7;
  }
  ans -= sub;
  ans %= (long long int)1e9 + 7;
  while (ans < 0) ans += (long long int)1e9 + 7;
  cout << ans << endl;
}
