#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
constexpr int N = 10, MOD = 1000000007;
int C, T;
int n, k;
struct Edge
{
    int u, v, id;
} e[N]; // de
vector<int> node[N];
int cnt = 0;
int key[N] = {};

vector<int> newn[N]; // newnode
int newc = 0;        // cnt for new edge
int ans = 0;
bool vis[N] = {};
int stop;
void dfs(int s)
{
    vis[s] = true;
    for (int i = 0; i < newn[s].size(); i++)
    {
        int next = newn[s][i];
        if (vis[next] == false)
        {
            if (i != 0)
                ans++;
            dfs(next);
        }
    }
}

signed main()
{
    freopen("traverse.in", "r", stdin);
    freopen("traverse.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> C >> T;
    while (T--)
    {
        // init iskey cnt node e newn newc vis
        memset(key,0,sizeof(key));
        cnt = 0;
        memset(node,0,sizeof(node));
        memset(e,0,sizeof(e));
        memset(newn,0,sizeof(newn));
        newc = 0;
        ans = 0;
        cin >> n >> k;
        for (int i = 1; i <= n - 1; i++)
        {
            int u, v;
            cin >> u >> v;
            e[cnt++] = {u, v, i};
            e[cnt++] = {v, u, i};
            node[u].push_back(i);
            node[v].push_back(i);
        }
        for (int i = 1; i <= k; i++)
        {
            cin >> key[i];
        }
        for (int i = 1; i < n; i++)
        {
            for (auto j : node[i])
            {
                for (auto k : node[i])
                {
                    if (j != k)
                    {
                        newc++;
                        newn[j].push_back(k);
                    }
                }
            }
        }
        for (int i = 1; i <= k; i++)
        {
            memset(vis,0,sizeof(vis));
            stop = key[i];
            dfs(key[i]);
            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}
/*
1 2
4 1
1 2
2 3
2 4
1
4 1
1 2
2 3
2 4
1

*/