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

typedef long long LL;
typedef unsigned long long ULL;
typedef __int128 i128;

LL read() {
	LL sum=0,flag=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') flag=-1; c=getchar();}
	while(c>='0'&&c<='9') {sum=sum*10+c-'0'; c=getchar();}
	return sum*flag;
}

const int N=5e5+10,M=21;
int n,q;
int deg[N],lg[N];
vector<int> g[N];
struct node {
	int l,r,k,id;
}a[N];

namespace Subtask1 {
	int dep[N],fa[N][21],lca[N][21];
	
	void dfs(int nd,int pa) {
		dep[nd]=dep[pa]+1;
		for(int i=1;i<=20;i++) fa[nd][i]=fa[fa[nd][i-1]][i-1];
		for(int x:g[nd]) {
			if(x==pa) continue;
			fa[x][0]=nd;
			dfs(x,nd);
		}
	}
	
	int find(int x,int y) {
		if(dep[x]<dep[y]) swap(x,y);
		for(int i=20;i>=0;i--) {
			if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
		}
		if(x==y) return y;
		for(int i=20;i>=0;i--) {
			if(fa[x][i]!=fa[y][i]) {
				x=fa[x][i];
				y=fa[y][i];
			}
		}
		return fa[x][0];
	}
	
	int calc(int l,int r) {
		int k=lg[r-l+1];
		return find(lca[l][k],lca[r-(1<<k)+1][k]);
	}
	
	void sol() {
		dfs(1,0);
		for(int i=1;i<=n;i++) lca[i][0]=i;
		for(int j=1;j<=20;j++) {
			for(int i=1;i+(1<<j)-1<=n;i++) {
				lca[i][j]=find(lca[i][j-1],lca[i+(1<<j-1)][j-1]);
			}
		}
		for(int ii=1;ii<=q;ii++) {
			auto t=a[ii];
			int l=t.l,r=t.r,k=t.k;
			int ans=0;
			for(int i=l;i+k-1<=r;i++) {
				ans=max(ans,dep[calc(i,i+k-1)]);
			}
			cout<<ans<<'\n';
		}
	}
}

namespace Subtask2 {
	void sol() {
		
	}
}

int main() {
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);

	lg[0]=-1; 
	for(int i=1;i<=5e5;i++) {
		lg[i]=lg[i/2]+1;
	}
	n=read();
	for(int i=1;i<n;i++) {
		int u=read(),v=read();
		g[u].push_back(v);
		g[v].push_back(u);
		deg[u]++; deg[v]++;
	}
	q=read();
	int flag=1;
	for(int i=1;i<=q;i++) {
		int l=read(),r=read(),k=read();
		a[i]={l,r,k,i};
		if(r-l+1!=k) flag=0;
	}

	Subtask1::sol();
	

	return 0;
}










