#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef pair <int, int> PII;
const int N = 5e5 + 5, P = 1e9 + 7;
int c, t, n, k, ed[N];
PII eg[N];
vector <int> G[N];

int idx, h[N];
struct edge{int to, nxt;}e[N << 1];
void addEdge(int u, int v)
{
	e[++idx] = (edge){v, h[u]};
	h[u] = idx;
}

int sum[N];
bool vis[N];
void DFS(int u, int f)
{
	int son = 0;sum[u] = 0;
	vis[u] = true;
	for(int i = h[u];i;i = e[i].nxt)
	{
		int v = e[i].to;
		if(vis[v])continue;son++;
		DFS(v, u), sum[u] = (sum[u] + sum[v]) % P;
	}
	if(!son)sum[u] = 1;
	vis[u] = false;
}

int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	scanf("%d%d", &c, &t);
	while(t--)
	{
		scanf("%d%d", &n, &k);
		for(int i = 1;i < n;i++)scanf("%d %d", &eg[i].first, &eg[i].second), G[eg[i].first].push_back(i), G[eg[i].second].push_back(i);
		for(int i = 1;i <= k;i++)scanf("%d", &ed[i]);
		if(c == 18){puts("1");continue;}
		else if(c <= 6)
		{
			for(int i = 1;i <= n;i++)
				for(int x : G[i])
					for(int y : G[i])
						if(x != y)
							addEdge(x, y);
			DFS(ed[1], 0), printf("%d\n", sum[ed[1]]);
		}
	}
}
