#include<bits/stdc++.h>
using namespace std;
int n,u,v,q,l[500001],r[500001],k[500001],f[500001][20],dep[500001],st[500001][20],lg[500001],p[20];
vector<int>e[500001];
int d_1;
bool falb;
inline int read(){
	int num = 0;
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	while(c >= '0' && c <= '9') num = num * 10 + c - '0',c = getchar();
	return num; 
}
void sch(int u,int fa){
	f[u][0] = fa;
	for(int i = 1;i <= 19;i ++){
		f[u][i] = f[f[u][i - 1]][i - 1];
	}
	dep[u] = dep[fa] + 1;
	for(auto v : e[u]){
		if(v == fa){
			continue;
		}
		sch(v,u);
	}
	return;
}
inline int lca(int x,int y){
	if(dep[x] < dep[y]) swap(x,y);
	for(int i = 19;i >= 0;i --) if(dep[f[x][i]] >= dep[y]) x = f[x][i];
	if(x == y) return x;
	for(int i = 19;i >= 0;i --) if(f[x][i] != f[y][i]) x = f[x][i],y = f[y][i];
	return f[x][0]; 
}
inline void solve1(){
	for(int i = 1;i <= q;i ++){
		int ans = 0;
		for(int j = l[i];j <= r[i] - k[i] + 1;j ++){//Çø¼äÆðµã 
			int x = j;
			for(int m = j + 1;m <= j + k[i] - 1;m ++){
				x = lca(x,m);
			}
			ans = max(ans,dep[x]);
		}
		printf("%d\n",ans);
	}
	return;
}
inline void stpre(){
	for(int i = 0;i <= 19;i ++) p[i] = 1 << i;
	lg[1] = 0;
	for(int i = 2;i <= n;i ++) lg[i] = lg[i >> 1] + 1;
	for(int i = 1;i <= n;i ++) st[i][0] = i;
	for(int i = 1;i <= lg[n];i ++){
		for(int j = 1;j <= n - p[i] + 1;j ++){
			st[j][i] = lca(st[j][i - 1],st[j + p[i - 1]][i - 1]);
		}
	}
	return;
}
inline int askst(int l,int r){
	int len = r - l + 1;
	return lca(st[l][lg[len]],st[r - p[lg[len]] + 1][lg[len]]);
}
inline void solve2(){
	stpre();
	for(int i = 1;i <= q;i ++){
		int ans = 0;
		for(int j = l[i];j <= r[i] - k[i] + 1;j ++){
			ans = max(ans,dep[askst(j,j + k[i] - 1)]); 
		} 
		printf("%d\n",ans);
	}
}
inline void solveB(){
	stpre();
	for(int i = 1;i <= q;i ++){
		printf("%d\n",dep[askst(l[i],r[i])]);
	}
	return;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n = read();
	for(int i = 1;i < n;i ++){
		u = read(),v = read();
		e[u].push_back(v),e[v].push_back(u);
	}
	sch(1,0);
	q = read();
	for(int i = 1;i <= q;i ++){
		l[i] = read(),r[i] = read(),k[i] = read();
		if(k[i] != r[i] - l[i] + 1){
			falb = true;
		}
	}
	
	if(n <= 500 && q <= 500){
		solve1(); 
		return 0;
	} 
	if(n <= 5000 && q <= 5000){
		solve2();
		return 0;
	}
	if(!falb){
		solveB();
		return 0;
	}
	
	solve2();

	return 0;
}




//11:05 finish 1~5   B   32pts
