n,m=list(map(int,input().split()))

i,d=0,[1]*(n+1)

while i<n:d[i+1]=((m-i)*((m-n+i)*d[i]+i*d[i-1]*(m-i+1)))%(10**9+7);i+=1

print((d[-1]))
n,m=list(map(int,input().split()))

i,a,b=0,1,0

while i<n:c=((m-i)*((m-n+i)*a+i*b*(m-i+1)))%(10**9+7);i+=1;a,b=c,a

print(a)
n, m = list(map(int, input().split()))
i, d = 0, [1] * (n + 1)
while i < n:
    d[i + 1] = ((m - i) * ((m - n + i) * d[i] + i * d[i - 1] * (m - i + 1))) % (
        10**9 + 7
    )
    i += 1
print((d[-1]))

n, m = list(map(int, input().split()))
i, a, b = 0, 1, 0
while i < n:
    c = ((m - i) * ((m - n + i) * a + i * b * (m - i + 1))) % (10**9 + 7)
    i += 1
    a, b = c, a
print(a)

-i, d = 0, [1] * (n + 1) +i, a, b = 0, 1, 0 -    d[i + 1] = ((m - i) * ((m - n + i) * d[i] + i * d[i - 1] * (m - i + 1))) % ( -        10**9 + 7 -    ) +    c = ((m - i) * ((m - n + i) * a + i * b * (m - i + 1))) % (10**9 + 7) -print((d[-1])) +    a, b = c, a +print(a)