#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int k;
int ha[N], dep[N], lg[N], d[N*4], fa[N][30];
struct Tree{
	int x, y, n;
}t[N*2];
void cun(int x,int y){
	t[++k].x=x, t[k].y=y;
	t[k].n=ha[x], ha[x]=k;
}
void dfs(int x,int lst){
	dep[x]=dep[lst]+1;
	fa[x][0]=lst;
	for(int i=1;i<=lg[dep[x]]-1;i++) fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int i=ha[x];i;i=t[i].n){
		int y=t[i].y;
		if(y==lst)continue;
		dfs(y,x);
	}
}
int LCA(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	while(dep[x]>dep[y]){
		int op=lg[dep[x]-dep[y]]-1;
		x=fa[x][op];
	}
	if(x==y)return x;
	for(int i=lg[dep[x]]-1;i>=0;i--){
		if(fa[x][i]!=fa[y][i]){
			x=fa[x][i], y=fa[y][i];
		}
	}
	return fa[x][0];	
}
void build(int p,int l,int r){
	if(l==r){
		d[p]=l;
		return;
	}
	int mid=l+((r-l)>>1);
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	if(l==1){
		d[p]=1;
		return;
	}
	d[p]=LCA(d[p*2],d[p*2+1]);
}
int getsum(int p,int l,int r,int al,int ar){
	if(al<=l&&r<=ar){
		return d[p];
	}
	int mid=l+((r-l)>>1), x=-1, y=-1;
	if(al<=mid)x=getsum(p*2,l,mid,al,ar);
	if(mid<ar)y=getsum(p*2+1,mid+1,r,al,ar);
	if(x!=-1&&y!=-1)return LCA(x,y);
	if(x!=-1&&y==-1)return x;
	if(x==-1&&y!=-1)return y;
	return 0;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	for(int i=1;i<=N-2;i++){
		lg[i]=lg[i>>1]+1;
	}
	int n, u, v;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		cun(u,v);
		cun(v,u);
	}
	dfs(1,0);
	build(1,1,n);
	int Q;
	scanf("%d",&Q);
	while(Q--){
		int l, r, len;
		scanf("%d%d%d",&l,&r,&len);
		int ans=1;
		for(int i=max(2,l);i+len-1<=r;i++){
			ans=max(ans,dep[getsum(1,1,n,i,i+len-1)]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

