#include <bits/stdc++.h>
#define int long long
using namespace std;
pair<int,int> e[100001];
signed main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	scanf("%lld%lld",&c,&T);
	srand(time(0));
	while(T--)
	{
		int n,k;
		scanf("%lld%lld",&n,&k);
		for(int i=1;i<n;i++)
		{
			scanf("%lld%lld",&e[i].first,&e[i].second);
		}
		for(int i=1;i<=k;i++)
		{
			int t;
			scanf("%lld",&t);
			cout<<rand()%10<<'\n';
		}
	}
	return 0;
}

