#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
namespace solve{
	inline ll read(){
		ll tmp=1,f=0;
		char a=getchar();
		while(a<'0' or a>'9')tmp=a=='-'?-1:tmp,a=getchar();
		while(a>='0' and a<='9')f=(f<<3)+(f<<1)+(a^48),a=getchar();
		return tmp*f;
	}
	inline void write(ll x){
		if(x<0)putchar('-'),x=-x;
		if(x>9)write(x/10);
		putchar(x%10+'0');
	}
	const int N=5e5+5,mod=1e9+7;
	int n,m,siz[N],lg[N],dep[N],fa[21][N],st[21][N],dfn[N],id;
	std::vector<int>G[N];
	inline void dfs(int u,int ff){
		fa[0][dfn[u]=++dfn[0]]=ff,dep[u]=dep[ff]+1;
		for(int i=0;i<G[u].size();i++)
			if(G[u][i]!=ff)dfs(G[u][i],u);
	}
	inline int chkmax(int x,int y){return dfn[x]<dfn[y]?x:y;}
	inline int LCA(int u,int v){
		if(u==v)return u;
		if(dfn[u]>dfn[v])std::swap(u,v);
		u=dfn[u],v=dfn[v];
		int k=lg[v-u++];
		return chkmax(fa[k][u],fa[k][v-(1<<k)+1]);
	}
	inline void init(){
		lg[0]=-1;
		for(int i=1;i<=n;i++)lg[i]=lg[i/2]+1;
		for(int i=1;i<=20;i++)
			for(int j=1;j+(1<<i)-1<=n;j++)
				fa[i][j]=chkmax(fa[i-1][j],fa[i-1][j+(1<<i-1)]);
		for(int i=1;i<=n;i++)st[0][i]=i;
		for(int i=1;i<=20;i++)
			for(int j=1;j+(1<<i)-1<=n;j++)
				st[i][j]=LCA(st[i-1][j],st[i-1][j+(1<<i-1)]);
	}
	void main(){
		freopen("query.in","r",stdin);
		freopen("query.out","w",stdout);
		n=read();
		for(int i=1;i<=n-1;i++){
			int u=read(),v=read();
			G[u].push_back(v),G[v].push_back(u);
		}
		dfs(1,0),init();
		m=read();
		while(m--){
			int l=read(),r=read(),k=read(),ans=0;
			int t=lg[k];
			for(int i=l;i+k-1<=r;i++){
				int lca=LCA(st[t][i],st[t][i+k-(1<<t)]);
				ans=std::max(ans,dep[lca]);
			}
			write(ans),putchar('\n');
		}
		return;
	}
}
int main(){
	solve::main();
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4

*/
