#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,num[21][2000005],dep[500005],dfn[500005],cnt,lg[2000005],mi[21];
vector<int> vc[500005];
void dfs(int h,int fa){
	dfn[h]=++cnt;
	num[0][cnt]=h;
	dep[h]=dep[fa]+1;
	for(auto x:vc[h]){
		if(x!=fa) dfs(x,h);
		++cnt;
		num[0][cnt]=h;
	}
}
int lca(int x,int y){
	if(dfn[x]>dfn[y]) swap(x,y);
	int k=lg[dfn[y]-dfn[x]+1];
	if(dep[num[k][dfn[x]]]<dep[num[k][dfn[y]-mi[k]+1]]) return num[k][dfn[x]];
	return num[k][dfn[y]-mi[k]+1];
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	mi[0]=1;
	for(int i=1;i<=20;i++) mi[i]=mi[i-1]*2;
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		vc[u].push_back(v);
		vc[v].push_back(u);
	}
	dfs(1,0);
	for(int i=1,j=2;i<=20;i++,j*=2){
		for(int x=1;x+j-1<=cnt;x++){
			if(dep[num[i-1][x]]<dep[num[i-1][x+j/2]]) num[i][x]=num[i-1][x];
			else num[i][x]=num[i-1][x+j/2];
		}
		for(int x=j/2;x<j;x++) lg[x]=i-1;
	}
	for(int x=1048576;x<=cnt;x++) lg[x]=20;
	int q;
	scanf("%d",&q);
	while(q--){
		int l,r,k,ans=0;
		scanf("%d%d%d",&l,&r,&k);
		for(int i=l;i+k-1<=r;i++){
			int j=i+k-1;
			int LCA=i;
			for(int x=i+1;x<=j;x++) LCA=lca(LCA,x);
			ans=max(ans,dep[LCA]);
		}
		printf("%d\n",ans);
	}
	return 0;
}
