#include <bits/stdc++.h>
#define LL long long
#define sl(s) strlen(s)
#define endline puts("")
#define pii pair<int, int>
#define pr_q priority_queue
#define debug puts("DEBUG.")
using namespace std;
const int N = 500 + 10;
const int inf = ~0u >> 2;
const int p = 1e9 + 7;
int cid,ct;
int n,k,f[N][N];
inline int read()
{
	int x = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9')
		ch = getchar();
	while(ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0',ch = getchar();
	return x;
}
namespace sub1
{
	void main()
	{
		while(ct--)
			puts("1");
	}
}
namespace sub2
{
	void main()
	{
		while(ct--)
		{
			n = read(),k = read();
			int fc1 = 1,fc2 = 1;
			for(int i = 1,u,v;i <= n - 1;i++)
				read(),read();
			for(int i = 1,x;i <= k;i++)
				read();
			for(int i = 1;i <= n - 3;i++)
				fc1 = 1ll * fc1 * i % p;
			fc2 = 1ll * fc1 * (n - 2) % p;
			if(k == 1)
			{
				printf("%d\n" , fc2);
			}
			else
			{
				printf("%d\n" , (1ll * k * fc2 % p - 1ll * k * (k - 1) / 2 % p * fc1 % p + p) % p );
			}
		}
	}
}
int main()
{
//	system("fc traverse10.out traverse10.ans");
	freopen("traverse.in" , "r" , stdin);
	freopen("traverse.out" , "w" , stdout);
	cid = read(),ct = read();
	if(cid == 18)
		sub1::main();
	if(19 <= cid && cid <= 21)
		sub2::main();
	return 0;
}

