#include<bits/stdc++.h>
using namespace std;
int n,q,dep[500010],dpcnt;
vector<int>ma[500010];
void dfs(int x,int fa)
{
	dep[x] = (++dpcnt);
	for(int t:ma[x])
	{
		if(t==fa)
			continue;
		dfs(t,x);
	}
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	scanf("%d",&n); 
	for(int i=1,u,v;i<=n;i++)
	{
		scanf("%d%d",&u,&v);
		ma[u].push_back(v);	
	}
	dfs(1,0);
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		printf("1\n");
	}
	return 0;
} 
