#include<bits/stdc++.h>
using namespace std;
#define MaxN 100010
#define M 1000000007
int imp[MaxN];
int dp[MaxN];
int n,m;
int main(){
	srand(time(NULL));
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int T;cin>>T;while(T--){
		cin>>n>>m;
		for(int i=1;i<=n-1;i++){
			int u,v;
			cin>>u>>v;
		}
		for(int i=1;i<=m;i++)
			cin>>imp[i];
		cout<<rand()%5<<endl; 
	}
	return 0;
}
