#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;

int n;
int dep[500005];
int kidd[500005];
bool v[500005];
//vector<int> treee[50000000];
int treee[500005];

void dfs(int p, int depp){
//	printf("%d %d\n",p,v[p]);
	v[p] = true;
	dep[p] = depp;
	
	if(!v[treee[p]])
	{
		kidd[p] = treee[p];
		dfs(treee[p], depp+1);
	}
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	scanf("%d",&n);
	for(int i=1; i<=n; i++) kidd[i] = i;
	for(int i=1; i<n; i++){
		int u,v;
		scanf("%d%d",&u,&v);
//		treee[u].push_back(v);
//		treee[v].push_back(u);
		treee[u] = v;
		treee[v] = u;
	}
	
	dfs(1, 0);
	
//	for(int i=1; i<=n; i++){
//		printf("<%d>\n",dep[i]);
//	}
	
	int q;
	scanf("%d",&q);
	for(int a=1; a<=n; a++){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(dep[l] > dep[r]) swap(l,r);
		while(dep[r]-dep[l] > k){
			l = kidd[l];
		}
		printf("%d\n",dep[l]);
	}
	
	return 0;
}
