#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,m;
struct node{
	int to,nxt;
}e[maxn<<1];
int head[maxn],cnt_edge;
void add_edge(int from,int to){
	e[++cnt_edge]={to,head[from]},head[from]=cnt_edge;
}void solve(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
}signed main(){
	scanf("%*d%d",&t);
	while(t--){
		solve();
	}
	return 0;
}
