import Data.Int
import Data.Ratio

import Data.Graph.Inductive.Graph
import Data.Graph.Inductive.PatriciaTree
import Control.Monad
import Data.List

main = do
  [n,k]<-map read.words<$>getLine
  edges<-replicateM(n-1)$(\[a,b]->(read a,read b)).words<$>getLine
  print$solve n (Mod k) edges

solve :: Int->ModInt->[Edge]->ModInt
solve n k edges = k * dfs 1 [(0,1)] where
  cld1 = child graph 1 0
  graph = mkUGraph [1..n] edges :: UGr
  dfs _ [] = 1
  dfs b ((p,n):g) = perm(k-b)nc * dfs 2(cld++g) where
    cld = zip(repeat n)$child graph n p
    nc = fromIntegral$length cld

modulo = 10^9+7

newtype ModInt = Mod Int deriving (Eq)

instance Show ModInt where
  show (Mod a) = show a
instance Bounded ModInt where
  maxBound = Mod $ modulo - 1
  minBound = 0
-- Caution! If (value>=modulo), this does not work.
instance Enum ModInt where
  toEnum a = Mod $ mod a modulo
  fromEnum (Mod a) = a
instance Num ModInt where
  (Mod a) + (Mod b) = Mod $ mod (a+b) modulo
  (Mod a) * (Mod b) = Mod $ mod (a*b) modulo
  abs = id
  signum = const 1
  fromInteger a = Mod $ fromIntegral $ mod a $ fromIntegral modulo
  negate 0 = 0
  negate (Mod a) = Mod $ modulo - a
instance Fractional ModInt where
  recip a = a ^ (modulo-2)
  fromRational r = Mod (n * signum d) / Mod (abs d) where
    [n,d] = [fromIntegral] <*> ( [numerator,denominator] <*> [r] )

fact n = product[1..n]
comb n r = product[n-r+1..n] / fact r
perm n r = product[n-r+1..n]