#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7,n,t,m,v,x[100005],y,las,s,dan,wk;
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<n;++i)
		cin>>v>>y;
		cin>>n;
		for(int i=1;i<=n;++i)
		{
			cin>>m>>v>>y;
			cout<<1<<endl;
		}
	}
	return 0;
}
