#include<bits/stdc++.h>
using namespace std;
const int N=5e5+2; 
int n,u,v,lg2[N],dfn[N],dep[N],st[19][N],a[19][N],Q,l,r,k;
vector<int>g[N];
void dfs(int u,int fa){
	dfn[u]=++dfn[0];
	st[0][dfn[u]]=fa;
	for(int v:g[u])if(v!=fa)dep[v]=dep[u]+1,dfs(v,u);
}
int getmin(int x,int y){return dfn[x]<dfn[y]?x:y;}
int LCA(int x,int y){
	if(x==y)return x;
	x=dfn[x],y=dfn[y];
	if(x>y)swap(x,y);
	int k=lg2[y-x++];
	return getmin(st[k][x],st[k][y-(1<<k)+1]);
}
int ask(int x,int y){
	int k=lg2[y-x+1];
	return LCA(a[k][x],a[k][y-(1<<k)+1]);
}
signed main(){
	freopen("query.in","r",stdin);freopen("query.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n,lg2[0]=-1;
	for(int i=1;i<=n;i++)lg2[i]=lg2[i>>1]+1;
	for(int i=1;i<n;i++)cin>>u>>v,g[u].push_back(v),g[v].push_back(u);
	dep[1]=1,dfs(1,0);
	for(int i=1;i<=18;i++)for(int j=1;j+(1<<i)-1<=n;j++)st[i][j]=getmin(st[i-1][j],st[i-1][j+(1<<i-1)]);
	for(int i=1;i<=n;i++)a[0][i]=i;
	for(int i=1;i<=18;i++)for(int j=1;j+(1<<i)-1<=n;j++)a[i][j]=LCA(a[i-1][j],a[i-1][j+(1<<i-1)]);
	for(cin>>Q;Q--;){
		cin>>l>>r>>k;
		int ans=0;
		for(int i=l;i+k-1<=r;i++)ans=max(ans,dep[ask(i,i+k-1)]);
		cout<<ans<<'\n';
	}
}
