#include<bits/stdc++.h>
using namespace std;
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c, T; scanf("%d%d", &c, &T);
	while (T--) {
		int n, k; scanf("%d%d", &n, &k);
		int x, y; 
		for (int i = 1; i < n; i++)
		    scanf("%d%d", &x, &y);
		int ans = k;
		for (int i = 1; i <= k; i++) {
			scanf("%d", &x);
			if (x == 1 || x == n - 1) ans--;
		}
		printf("%d\n", ans);
	}
	return 0;
}
