#include using namespace std; const int MOD = 1e9+7; const int MAXN = 100010; struct Edge { int to, next; } edge[MAXN*2]; int head[MAXN], tot; void init() { tot = 0; memset(head, -1, sizeof(head)); } void addedge(int u, int v) { edge[tot].to = v; edge[tot].next = head[u]; head[u] = tot++; } int dep[MAXN]; int du[MAXN]; int fa[MAXN]; void dfs(int u, int pre) { du[u] = 0; fa[u] = pre; for (int i = head[u]; i != -1 ;i = edge[i].next) { int v = edge[i].to; if (v == pre) continue; du[u]++; dep[v] = dep[u]+1; dfs(v, u); } } long long pow_m(long long a, long long n) { long long ret = 1; long long tmp = a%MOD; while (n) { if (n&1) ret = ret*tmp%MOD; n >>= 1; tmp = tmp*tmp%MOD; } return ret; } int main() { int T; scanf("%d", &T); while (T--) { int n, m; scanf("%d%d", &n, &m); init(); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); addedge(u, v); addedge(v, u); } dep[1] = 0; dfs(1, 1); long long tmp0 = 1; long long tmp1 = 0; int now = m; if (now == 1) { puts("1"); continue; } do { now = fa[now]; if (now != 1) { tmp1 = tmp1*pow_m(du[now]+1, MOD-2)%MOD; tmp1 = (tmp1 + tmp0*pow_m(du[now]+1, MOD-2)%MOD*pow_m(du[now], MOD-2)%MOD*(du[now]-1)%MOD)%MOD; tmp0 = tmp0*pow_m(du[now]+1, MOD-2)%MOD; } else { tmp1 = tmp1*pow_m(du[now], MOD-2)%MOD; tmp1 = (tmp1 + tmp0*pow_m(du[now], MOD-2)%MOD*pow_m(du[now]-1, MOD-2)%MOD*(du[now]-1)%MOD )%MOD; tmp0 = tmp0*pow_m(du[now], MOD-2)%MOD; } } while (now != 1); long long ans = (tmp0 + tmp1)%MOD; printf("%d\n", (int) ans); } return 0; }