module queue
  implicit none
  type :: JagArray
    integer,allocatable :: array(:)
  end type JagArray
  contains
  subroutine InitiationJaggArray(N,arrays)
    integer(16)::N
    type(JagArray),allocatable,dimension(:)::arrays
    integer(16)::i
    allocate(arrays(N))
    do i=1,N
      arrays(i)%array=[integer::]
    end do
    return
  end subroutine
  subroutine push(A,b)
    integer,allocatable,dimension(:)::A
    integer::b
    A=[A,b]
  end subroutine
  subroutine pop(A)
    integer,allocatable,dimension(:)::A
    A=A(2:)
  end subroutine
end module queue

use queue
integer(16)N,K
integer a,b
type(JagArray),allocatable,dimension(:)::EDGE
integer(16) ans
integer(16) mo
integer(16) i
logical,allocatable,dimension(:)::visited
read*,N,K
mo=10**9+7
call InitiationJaggArray(N,EDGE)
do i=1,N-1
  read*,a,b
  call push(EDGE(a)%array,b)
  call push(EDGE(b)%array,a)
end do

allocate(visited(N))
visited=.False.
ans=k
call dfs(EDGE,1_16,ans)
print"(i0)",ans

contains

recursive subroutine dfs(EDGE,node,ans)
  implicit none
  integer(16),intent(in)::node
  integer(16),intent(inout)::ans
  type(JagArray),allocatable,dimension(:)::EDGE
  integer(16)::c
  integer(16)::e,i
  visited(node)=.TRUE.
  c=2_16
  if(node==1)c=1_16
  do i=1,size(edge(node)%array)
    e=edge(node)%array(i)
    if(visited(e))cycle
    ans=mod(ans*max(0,k-c),mo)
    c=c+1_16
    call dfs(EDGE,e,ans)
  end do
  return
end subroutine dfs
end