#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n;
int e[2*N],ls[N],nx[2*N],em;
int q;

int fa[N][25];
int dep[N];

int ans;
int t[4*N];
void insert(int x,int y){
	e[++em]=y;
	nx[em]=ls[x];
	ls[x]=em;
	return;
}
void dfs(int x,int father){
	fa[x][0]=father;
	dep[x]=dep[father]+1;
	for(int i=1; i<=20; i++){
		fa[x][i]=fa[fa[x][i-1]][i-1];
	}
	for(int i=ls[x]; i; i=nx[i]){
		if(e[i]==father) continue;
		dfs(e[i],x);
	}
	return;
}
int lca(int x,int y){
	if(x==0||y==0) 
	return x|y;
	if(dep[x]<dep[y]) swap(x,y);
	while(dep[x]!=dep[y]){
		for(int i=0; i<=20; i++){
			if(dep[fa[x][i]]<dep[y]){
				if(i!=0) i--;
				x=fa[x][i];
				break;
			}
		}
	}
	while(x!=y){
		for(int i=0; i<=20; i++){
			if(fa[x][i]==fa[y][i]){
				if(i!=0) i--;
				x=fa[x][i];
				y=fa[y][i];
				break;
			}
		}
	}
	return x;
}
void build(int x,int l,int r){
	if(l==r){
		t[x]=l;
		return;
	}
	int mid=(l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
	t[x]=lca(t[x*2],t[x*2+1]);
	return; 
}
int find(int x,int l,int r,int L,int R){
	if(r<L||R<l) 
	return 0;
	if(L<=l&&r<=R){
		return t[x];
	}
	int mid=(l+r)/2;
	return lca(find(x*2,l,mid,L,R),find(x*2+1,mid+1,r,L,R));
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int u,v;
		scanf("%d%d",&u,&v);
		insert(u,v);
		insert(v,u);
	}
	dfs(1,0);
	build(1,1,n);
	scanf("%d",&q);
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		ans=0;
		for(int i=l; i+k-1<=r; i++){
			int p=find(1,1,n,i,i+k-1);
			ans=max(ans, dep[p] );
		} 
		printf("%d\n",ans);
	}
	return 0;
}
