#include <cstdio>
#include <iostream>
using namespace std;
const int N = 5e5+5;
struct Edge{
	int to, nxt;
}e[N+N];
int n, q, f[N][25], head[N], dep[N], lg[N], fa[N][25], idx;
inline void add(int u, int v){
	e[++idx] = (Edge){v,head[u]}; head[u] = idx;
}
void dfs(int u, int fat){
	fa[u][0] = fat;
	dep[u] = dep[fat]+1;
	for(int i=1; i<=20; ++i)
		fa[u][i] = fa[fa[u][i-1]][i-1];
	for(int i=head[u],v; i; i=e[i].nxt){
		v = e[i].to;
		if(v == fat) continue;
		dfs(v, u);
	}
}
inline int lca(int u, int v){
	if(dep[u] < dep[v]) swap(u, v);
	for(int i=0,dif=dep[u]-dep[v]; dif; ++i,dif>>=1)
		if(dif & 1) u = fa[u][i];
	if(u == v) return u;
	for(int i=20; i>=0; --i)
		if(fa[u][i] != fa[v][i]){
			u = fa[u][i]; v = fa[v][i];
		}
	return fa[u][0];
}
inline int querylca(int l, int r){
	int m = lg[r-l+1];
	return lca(f[l][m], f[r-(1<<m)+1][m]);
}
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i=1,u,v; i<n; ++i){
		scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	}
	scanf("%d", &q);
	dfs(1, 0);
	
	lg[1] = 0;
	for(int i=1; i<=n; ++i){
		if(i > 1) lg[i] = lg[i>>1]+1;
		f[i][0] = i;
	}
	for(int i=1; i<=lg[n]; ++i)
		for(int j=1; j+(1<<i)-1<=n; ++j)
			f[j][i] = lca(f[j][i-1],f[j+(1<<i-1)][i-1]);
	while(q--){
		int l, r, k, res=0;
		scanf("%d%d%d", &l, &r, &k);
		for(int i=l; i<=r-k+1; ++i)
			res = max(res, dep[querylca(i,i+k-1)]);
		printf("%d\n", res);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
