#include<bits/stdc++.h>
using namespace std;
namespace MAOJUN{

const int N=5e5+5;
int n,q,ql[N],qr[N],qk[N];
const int E=N<<1;
int tot=0,hd[N],to[E],nxt[E];
inline void Add(int u,int v){to[++tot]=v;nxt[tot]=hd[u];hd[u]=tot;}

namespace SLV1{
	inline bool chk(){
		if(n<=5000&&q<=5000)return 1;
		for(int i=1;i<=q;i++)if(qk[i]!=qr[i]-ql[i]+1)return 0;
		return 1;
	}
	int dfc=0,dfn[N],id[N],dep[N],lg[N],s1[20][N],s2[20][N],s3[20][N];
	void dfs(int u,int f){
		id[dfn[u]=++dfc]=u;dep[u]=dep[f]+1;s1[0][dfc]=dfn[f];s2[0][u]=s3[0][u]=dfc;
		for(int i=hd[u];i;i=nxt[i])if(to[i]!=f)dfs(to[i],u);
	}
	inline int LCA(int u,int v){
		if(u==v)return u;u=dfn[u];v=dfn[v];if(u>v)swap(u,v);u++;
		int k=lg[v-u+1];return id[min(s1[k][u],s1[k][v-(1<<k)+1])];
	}
	inline int Min(int l,int r){
		int k=lg[r-l+1];return min(s2[k][l],s2[k][r-(1<<k)+1]);
	}
	inline int Max(int l,int r){
		int k=lg[r-l+1];return max(s3[k][l],s3[k][r-(1<<k)+1]);
	}
	inline void slv(){
		for(int i=2;i<=n;i++)lg[i]=lg[i>>1]+1;
		dfs(1,0);
		for(int k=1;1<<k<=n;k++)for(int i=1;i+(1<<k)-1<=n;i++){
			s1[k][i]=min(s1[k-1][i],s1[k-1][i+(1<<k-1)]);
			s2[k][i]=min(s2[k-1][i],s2[k-1][i+(1<<k-1)]);
			s3[k][i]=max(s3[k-1][i],s3[k-1][i+(1<<k-1)]);
		}
		for(int i=1;i<=q;i++){
			int rs=0;
			for(int j=ql[i];j+qk[i]-1<=qr[i];j++)
				rs=max(rs,dep[LCA(id[Min(j,j+qk[i]-1)],id[Max(j,j+qk[i]-1)])]);
			printf("%d\n",rs);
		}
	}
}
inline void main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){scanf("%d%d",&u,&v);Add(u,v);Add(v,u);deg[u]++;deg[v]++;}
	scanf("%d",&q);
	for(int i=1;i<=q;i++)scanf("%d%d%d",&ql[i],&qr[i],&qk[i]);
	if(SLV1::chk())return SLV1::slv();
}

}int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	MAOJUN::main();
	return 0;
}