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

#define LL long long
#define pb emplace_back
#define fr first
#define sc second
typedef const int Int;
typedef pair<int,int> pii;

Int N=5e5+5;

int n,q;

int lg2[N]={0,0,1};

vector <int> G[N];

int fa[N][20],dep[N],lca[N][20];

void init(Int &u,Int &p){
	dep[u]=dep[p]+1;
	lca[u][0]=u;
	fa[u][0]=p;
	for(Int &v:G[u]){
		if(v==p)continue;
		init(v,u);
	}
}

int LCA(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	int len=dep[x]-dep[y];
	for(int i=0;len;len>>=1,i++)if(len&1)x=fa[x][i];
	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 query(Int &l,Int &r){
	int len=lg2[r-l+1];
	return min(dep[lca[l][len]],dep[lca[r-(1<<len)+1][len]]);
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=3;i<=n;i++)lg2[i]=lg2[i>>1]+1;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].pb(v),G[v].pb(u);
	}
	init(1,1);
	for(int p=1;p<20;p++){
		for(int i=1;i<=n;i++)fa[i][p]=fa[fa[i][p-1]][p-1];
	}
	for(int p=1;p<20;p++){
		for(int i=1;i<=n;i++)lca[i][p]=LCA(lca[i][p-1],lca[i+(1<<(p-1))][p-1]);
	}
	scanf("%d",&q);
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		int ans=1;
		for(int i=l;i+k-1<=r;i++)ans=max(ans,query(i,i+k-1));
		printf("%d\n",ans);
	}
	return 0;
}




















