#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILL(x,c) memset(x,c,sizeof(x))

using namespace std;

const double eps = 1e-8;

#define PB push_back
#define MP make_pair

typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long double> VD;
typedef pair<int,int> PII;
typedef long long int64;
typedef long long ll;
typedef unsigned int UI;
typedef long double LD;
typedef unsigned long long ULL;

const int V = 50000 + 100;
const ll MOD = 1000000000 + 7;

int inv[V];
int size[V], power2[V];
vector<int> adj[V];
ll hash[V], f[V];
int n, m;

int C(int x, int y) {
    assert(y < V);
    ll ret = 1;
    for (int i = 0; i < y; ++i) 
        ret = ret * (x-i) % MOD * inv[i+1] % MOD;
    return ret;
}
void dfs(int v, int fa) {
    vector<pair<int, int> > vec;
    map<int, int> mp;
    
    size[v] = 1;
    for (int i = 0; i < adj[v].size(); ++i) 
    if (adj[v][i] != fa) {
        int u = adj[v][i];
        dfs(u, v);
        vec.push_back(MP(hash[u], u));
        mp[hash[u]]++;
        size[v] += size[u];
    }
    
    f[v] = m;
    for (map<int,int>::iterator it = mp.begin(); it != mp.end(); ++it) {
        int k = it->second;
        int n = f[it->first];
        f[v] = (f[v] * C(n+k-1, k)) % MOD;
    }
    
    hash[v] = 0;
    sort(vec.begin(), vec.end());
    for (int i = 0; i < vec.size(); ++i) {
        int u = vec[i].second;
        hash[v] = (hash[v] * power2[size[u]*2] + hash[u]) % MOD;
    }
    hash[v] = (hash[v] * 2 + 1) % MOD;
}
void prepareInv(int n) {
    inv[1] = 1;
    for(int i = 2; i < n; i++) 
        inv[i] = (MOD - MOD/i) * inv[(int)(MOD%i)] % MOD;
        
    for (int i = 0; i < n; ++i)
        power2[i] = (i == 0) ? 1 : power2[i-1] * 2 % MOD;
}
int main() {
    int a, b;
    while (cin >> n >> m) {
        REP(i, n-1) {
            scanf("%d%d",&a, &b);
            a--; b--;
            adj[a].PB(b);
            adj[b].PB(a);
        }
        prepareInv(V);
        dfs(0, -1);
        cout << f[0] << endl;
    }
}