#include<bits/stdc++.h>

using namespace std;

int n; 
int x,y;
int q;
int l,r,k;

vector<int>v[500010];

int l2[500010];

int fa[500010][25];
int deep[500010];
int st[500010][25];

void dfs(int x,int f){
	deep[x]=deep[f]+1;
	fa[x][0]=f;
	for(int i=0;i<v[x].size();i++){
		int to=v[x][i];
		if(to==f) continue;
		dfs(to,x);
	}
}

int lca(int x,int y){
	if(deep[x]>deep[y]) swap(x,y);
	for(int i=22;i>=0;i--){
		if(deep[fa[y][i]]>=deep[x]) y=fa[y][i];
	}
	if(x==y) return x;
	for(int i=22;i>=0;i--){
		if(fa[y][i]!=fa[x][i]){
			y=fa[y][i];
			x=fa[x][i];
		}
	}
	return fa[x][0];
}

int query(int l,int r){
	int now=l2[r-l+1];
	return lca(st[l][now],st[r-(1<<now)+1][now]);
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	//freopen("qwq.out","w",stdout);
	
	scanf("%d",&n);
	
	for(int i=2;i<=n;i++){
		l2[i]=l2[i/2]+1;
	}
	
	for(int i=1;i<=n-1;i++){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0);
	
	for(int j=1;j<=22;j++){
		for(int i=1;i<=n;i++){
			fa[i][j]=fa[fa[i][j-1]][j-1];
		}
	}
	
	for(int i=1;i<=n;i++) st[i][0]=i;
	
	for(int j=1;j<=22;j++){
		for(int i=1;i<=n;i++){
			st[i][j]=lca(st[i][j-1],st[min(n,i+(1<<(j-1)))][j-1]);
		}
	}
	
	scanf("%d",&q);
	
	/*if(n<=5000&&q<=5000){
		solve();
	}*/
	
	while(q--){
		scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		for(int i=l;i+k-1<=r;i++){
			ans=max(ans,deep[query(i,i+k-1)]);
		}
		printf("%d\n",ans);
	}
	
	//printf("qwq %d\n",lca(4,5));
	
	//system("fc qwq.out query2.ans");
	
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
