#include<bits/stdc++.h>
using namespace std;
vector<int> s[100010];
vector<int> e[100010];
int st[100010];
int c,t,n,k,ans=1,m;
int h[100010],cnt[100010],dep=-1;
int a[1001][1010];
string ss;
unordered_set<string> mm;
bool vis[100010];
int dfs(int p,int f){
	if(vis[p]){
		return 0;
	}
	vis[p]=true;
	int u=p;
	for(auto v:e[u]){
		
		if(v!=f){
			dfs(v,u);
			dfs(v,u);
		}
	}
	return 0;
}
int main(){
	ifstream fin("traverse.in");
	ofstream fout("traverse.out");
	cin>>c>>t;
	while(t>0){
		t--;
		cin>>n>>k;
		if(k==1){
			for(int i=1;i<n;i++){
				int u,v;
				cin>>u>>v;
				if(!s[u].empty()){
					for(auto it:s[u]){
						e[it].push_back(i);
						e[i].push_back(it);
					}
				}
				if(!s[v].empty()){
					for(auto it:s[v]){
						e[it].push_back(i);
						e[i].push_back(it);
					}
				}
				s[u].push_back(i);
				s[v].push_back(i);
			}
			/*for(int i=1;i<n;i++){
				cout<<i<<"//";
				for(auto it:e[i])cout<<it<<" ";
				cout<<endl;
			} */
			
		}
	}
	return 0;
}
