#include<bits/stdc++.h>
using namespace std;
const int N=5e5+1;
int n,q,ans;
int Log2[N]; 
void initLog2(){
	Log2[1]=0;
	Log2[2]=1;
	for(int i=3;i<=n;++i){
		Log2[i]=Log2[i>>1]+1;
	}
}

struct Tree{
	vector<int>r[N];
	void addedge(int u,int v){
		r[u].push_back(v);
		r[v].push_back(u);
	}
	int fa[N],de[N],siz[N],hs[N];
	void dfs1(int x,int fath){
		fa[x]=fath;
		de[x]=de[fath]+1;
		siz[x]=1;
		hs[x]=0;
//		if(r[x].size()==0)return;
//		printf("%d\n",r[x].size());
		for(int v:r[x]){
			if(v==fath)continue;
			dfs1(v,x);
			siz[x]+=siz[v];
			if(siz[v]>siz[hs[x]]){
				hs[x]=v;
			}
		}
	}
	int top[N];
	void dfs2(int x,int tp){
		top[x]=tp;
		if(hs[x])dfs2(hs[x],tp);
		for(int v:r[x]){
			if(v==fa[x])continue;
			if(v==hs[x])continue;
			dfs2(v,v);
		}
	}
	int LCA(int a,int b){
		while(top[a]!=top[b]){
			if(de[top[a]]<de[top[b]])swap(a,b);
			a=fa[top[a]];
		}
		return ((de[a]>de[b])?b:a);
	}
}t;
struct ST{
	int r[30][N];
	void build(){
		for(int i=1;i<=n;++i){
			r[0][i]=i;
		}
		for(int i=1;i<=30;++i){
			for(int j=1;j+(1<<i)-1<=n;++j){
				r[i][j]=t.LCA(r[i-1][j],r[i-1][j+(1<<i-1)]);
			}
		}
	}
	int find(int ll,int rr){
		int x=Log2[rr-ll+1];
		return t.LCA(r[x][ll],r[x][rr-(1<<x)+1]);
	}
}st;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		t.addedge(u,v);
	}
	t.de[1]=0;
	t.siz[0]=0; 
	t.dfs1(1,1);
	t.dfs2(1,1);
	initLog2();
	st.build();
	scanf("%d",&q);
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		ans=0;
//		for(int len=k;len<=r-l+1;++len)
		for(int i=l;i+k-1<=r;++i){
			ans=max(ans,t.de[st.find(i,i+k-1)]);
		}printf("%d\n",ans);
	}
	return 0;
}

