N,K = gets.chomp.split(" ").map(&:to_i)
mat = readlines.map{|n| n.chomp.split(" ").map(&:to_i)}

@graph = Array.new(N+1){[]}
mat.each do |n|
    arr = @graph[n[0]]
    arr << n[1]
    @graph[n[0]] = arr
    arr = @graph[n[1]]
    arr << n[0]
    @graph[n[1]] = arr
end
def log(n)
    #p n
end

@q = []
@visited = []

def dfs(v, minus)
    @visited[v] = true
    @q << v
    num=1
    cands_number = K - 1
    while (tmp = @q.shift) do
        
        arr = @graph[tmp]
        arr.each do |n|
            next if @visited[n]
            num*= cands_number
            cands_number-=1
            num %= 1000000007
        end
        arr.each do |n|
            if not @visited[n]
                @visited[n] = true
                @q << n
            end
        end
        cands_number = K - 2
    end
    return num;
end
puts K * dfs(1,-1) % 1000000007