//64'
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,q;
vector <int> T[N];
int tot,dep[N],dfn[N<<1],p[N];
int lg[N<<1],st[N<<1][21];
int lca[N<<2];
void DFS(int u,int f,int d){
	dep[dfn[p[u]=(++tot)]=u]=d;
	for(auto v:T[u])
		if(v^f){
			DFS(v,u,d+1);
			dfn[++tot]=u;
		}
}
inline int MIN(int x,int y){
	return (dep[x]<dep[y]?x:y);
}
inline int LCA(int x,int y){
	x=p[x];y=p[y];
	if(x>y) swap(x,y);
	int k(lg[y-x+1]);
	return MIN(st[x][k],st[y-(1<<k)+1][k]);
}
void Build(int k,int l,int r){
	if(l==r){lca[k]=l;return;}
	int ls(k<<1),rs(k<<1|1),mid(l+r>>1);
	Build(ls,l,mid);Build(rs,mid+1,r);
	lca[k]=LCA(lca[ls],lca[rs]);
}
int Query(int k,int l,int r,int s,int t){
	if(s<=l&&r<=t) return lca[k];
	int ls(k<<1),rs(k<<1|1),mid(l+r>>1);
	if(mid<s) return Query(rs,mid+1,r,s,t);
	if(t<=mid) return Query(ls,l,mid,s,t);
	return LCA(Query(rs,mid+1,r,s,t),Query(ls,l,mid,s,t));
}
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);
		T[u].push_back(v);
		T[v].push_back(u);
	}
	DFS(1,0,1);
	for(int i(2);i<=tot;++i) lg[i]=lg[i>>1]+1;
	for(int i(1);i<=tot;++i) st[i][0]=dfn[i];
	for(int j(1);j<=lg[tot];++j)
		for(int i(1);i+(1<<j)-1<=tot;++i){
			st[i][j]=MIN(st[i][j-1],st[i+(1<<j-1)][j-1]);
		}
	Build(1,1,n);
	scanf("%d",&q);
	while(q--){
		int l,r,k;scanf("%d%d%d",&l,&r,&k);
		if(n<=5000){
			int ret(0);
			for(int i(l);i+k-1<=r;++i)
				ret=max(ret,dep[Query(1,1,n,i,i+k-1)]);
			printf("%d\n",ret);
		}
		else printf("%d\n",dep[Query(1,1,n,l,r)]);
	}
	return 0;
}
