#include<bits/stdc++.h>
#define eb emplace_back
using namespace std;
const int N=500005;
int n,Q,fa[N][20],L[N][20],deg[N],Log[N],dep[N];
vector<int>v[N];
void dfs(int x,int fat){
	fa[x][0]=fat;
	dep[x]=dep[fat]+1;
	for (int y:v[x])if (y!=fat)dfs(y,x);
}
void init(){
	for (int j=1;j<=19;++j)
		for (int i=1;i<=n;++i)
			fa[i][j]=fa[fa[i][j-1]][j-1];
}
int lca(int x,int y){
	if (dep[x]<dep[y])swap(x,y);
	int c=dep[x]-dep[y],s=0;
	while (c){
		if (c&1)x=fa[x][s];
		++s,c>>=1;
	}
	if (x==y)return x;
	for (int i=19;i>=0;--i)if (fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
int qry(int x,int y){
	int z=Log[y-x+1];
	return lca(L[x][z],L[y-(1<<z)+1][z]);
}
int main(){
	freopen("query.in","r",stdin);freopen("query.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for (int i=1,x,y;i<n;++i){
		cin>>x>>y;
		v[x].eb(y),v[y].eb(x);
		++deg[x],++deg[y];
	}
//	int s=0,ss=0;
//	for (int i=1;i<=n;++i)if (deg[i]==2)++s;else if (deg[i]==1)++ss;
//	if (s==n-2&&ss==2){
//		sub::solve();
//	}
	dfs(1,0);
	init();
	for (int i=2;i<=n;++i)Log[i]=Log[i>>1]+1;
	for (int i=1;i<=n;++i)L[i][0]=i;
	for (int j=1;j<=19;++j)
		for (int i=1;i+(1<<j)-1<=n;++i)
			L[i][j]=lca(L[i][j-1],L[i+(1<<(j-1))][j-1]);
	cin>>Q;
	for (int i=1;i<=Q;++i){
		int x,y,z,ans=0;
		cin>>x>>y>>z;
		for (int j=x;j<=y-z+1;++j)ans=max(ans,dep[qry(j,j+z-1)]);
		cout<<ans<<"\n";
	}
}
