#include<bits/stdc++.h>
using namespace std;
int top[500001],fa[500001],dep[500001],son[500001];
int lca[500001][20];
int n,q,s1,s2,k;
vector<int> fig[500001];
int dfs1(int s,int pa,int d){
	int siz=1,zson=s,msiz=0,tsiz;
	for(int i:fig[s]){
		if(i!=pa){
			dep[i]=d+1;
			fa[i]=s;
			tsiz=dfs1(i,s,d+1);
			siz+=tsiz;
			if(tsiz>msiz){
				zson=i;
				msiz=tsiz;
			}
		}
	}
	son[s]=zson;
	return siz;
}
void dfs2(int s,int pa,int ztop){
	for(int i:fig[s]){
		if(i!=pa){
			if(i==son[s]){
				top[i]=ztop;
				dfs2(i,s,ztop);
			}
			else{
				top[i]=i;
				dfs2(i,s,i);
			}
		}
	}
}
int LCA(int a,int b){
	while(top[a]!=top[b]){
		if(dep[top[a]]>dep[top[b]]){
			a=fa[top[a]];
		}
		else b=fa[top[b]];
	}
	return (dep[a]<dep[b])?a:b;
}
int log2(int a){
//	if(!a)return 0;
	int ans=0,t=1;
	while(t<=a){
		t<<=1;
		ans++;
	}
	return --ans;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
//	freopen("D:/down/day0/query/query2.in","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>s1>>s2;
		fig[s1].push_back(s2);
		fig[s2].push_back(s1);
	}
	dep[1]=1;fa[1]=1;
	dfs1(1,0,1);
	top[1]=1;
	dfs2(1,0,1);
	cin>>q;
	for(int i=1;i<=n;i++)lca[i][0]=i;
	for(int i=1;(1<<i)<=n;i++){
		for(int j=1;j+(1<<i)<=n;j++){
			int r=j+(1<<(i-1));
			lca[j][i]=LCA(lca[j][i-1],lca[r][i-1]);
		}
	}
	while(q--){
		cin>>s1>>s2>>k;
		int qans=1;
		for(int i=k;i<=s2-s1;i++){
			if(i==1){
				for(int j=s1;j<=s2;j++)
				qans=max(qans,dep[lca[j][0]]);
				continue;
			}
			for(int j=s1;j<s2-i;j++){
				int p1=log2(k),p2=0;
				p2=log2(k-(1<<p1))+1;
				int r=j+k-(1<<p2);
				qans=max(qans,dep[LCA(lca[j][p1],lca[r][p2])]);
			}
		}
		cout<<qans<<endl;
	}
	return 0;
}
