#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
struct edge{
	int to,nxt;
}e[maxn];
int cnt,head[maxn],n,dep[maxn],fa[maxn],siz[maxn],yfa[maxn],m;
void add(int u,int v){
	e[++cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
void dfs1(int x,int f){
	dep[x]=dep[f]+1;
	yfa[x]=f;
	siz[x]=1;
	int maxx=0;
	for(int i=head[x];i;i=e[i].nxt){
		if(e[i].to==f)continue;
		dfs1(e[i].to,x);
		siz[x]+=siz[e[i].to];
		maxx=max(maxx,siz[e[i].to]);
	}
	for(int i=head[x];i;i=e[i].nxt){
		if(e[i].to==f)continue;
		if(siz[e[i].to]==maxx){
			fa[e[i].to]=find(x);
			break;
		}
	}
}
int lca(int x,int y){
	while(find(x)!=find(y)){
		if(dep[find(x)]>dep[find(y)])swap(x,y);
		y=yfa[find(y)];
	}
	if(dep[x]>dep[y])return y;
	else return x;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("queue.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	dfs1(1,0);
	cin>>m;
	while(m--){
		int x,y,z,ans=0;
		cin>>x>>y>>z;
		for(int i=x;i+z-1<=y;i++){
			int __lca=i;
			for(int j=i+1;j<=i+z-1;j++)__lca=lca(__lca,j);
			ans=max(ans,dep[__lca]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}

