#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + (c - '0'), c = getchar();
  return f * x;
}
void MOD(int &x) {
  if (x >= 1000000007) x -= 1000000007;
}
int f[200010], a[200010], b[200010], inv[200010];
int power(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1ll * ans * a % 1000000007;
    a = 1ll * a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
int C(int n, int m) {
  return 1ll * f[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;
}
int main() {
  int n, k;
  n = read();
  k = read();
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = 1ll * f[i - 1] * i % 1000000007;
  inv[n] = power(f[n], 1000000007 - 2);
  for (int i = n; i >= 1; i--) inv[i - 1] = 1ll * inv[i] * i % 1000000007;
  a[0] = 1;
  for (int i = 1; i <= n * n; i++) a[i] = 1ll * a[i - 1] * (k - 1) % 1000000007;
  b[0] = 1;
  for (int i = 1; i <= n * n; i++) b[i] = 1ll * b[i - 1] * k % 1000000007;
  int ans = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) {
      int num = i * n + j * n - i * j;
      int w = 1ll * C(n, i) * C(n, j) % 1000000007 * a[num] % 1000000007 *
              b[n * n - num] % 1000000007;
      if ((i + j) & 1)
        MOD(ans += 1000000007 - w);
      else
        MOD(ans += w);
    }
  printf("%d\n", ans);
}
