#include <bits/extc++.h>
#define dbg(x) cerr << #x" = " << (x) << endl
#define debug(...) fprintf(stderr,__VA_ARGS__)
using ll = long long;
const int MAXN = 5e5 + 10;
using namespace std;
int n,q,lca[MAXN][20];
basic_string<int> p[MAXN];
struct HLD{
	int fa[MAXN],top[MAXN],dep[MAXN],sz[MAXN],wc[MAXN];
	void dfs1(int u,int f){
		fa[u] = f,sz[u] = 1,dep[u] = dep[f] + 1;
		for(int v : p[u]){
			if(v == f) continue;
			dfs1(v,u);
			sz[u] += sz[v];
			if(sz[v] > sz[wc[u]]) wc[u] = v;
		}
	}
	void dfs2(int u,int t){
		top[u] = t;
		if(wc[u]){
			dfs2(wc[u],t);
			for(int v : p[u]){
				if(v == wc[u] || v == fa[u]) continue;
				dfs2(v,v);
			}
		}
	}
	void init(){
		dfs1(1,0),dfs2(1,1);
	}
	int lca(int u,int v){
		while(top[u] != top[v]){
			if(dep[top[u]] < dep[top[v]]) swap(u,v);
			u = fa[top[u]];
		}
		return dep[u] < dep[v] ? u : v;
	}
} hld;

void init(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin.tie(0) -> ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 1,u,v;i < n;i++){
		cin >> u >> v;
		p[u] += v,p[v] += u;
		lca[i][0] = i;
	}
	cin >> q;
	hld.init();
	for(int k = 1;(1 << k) <= n;k++){
		for(int i = 1;i + (1 << k) - 1 <= n;i++){
			lca[i][k] = hld.lca(lca[i][k - 1],lca[i + (1 << (k - 1))][k - 1]);
		}
	}
}

int querylca(int l,int r){
	int k = __lg(r - l + 1);
	return hld.lca(lca[l][k],lca[r - (1 << k) + 1][k]);
}

int main(){
	init();
	for(int L,R,k;q;q--){
		// dbg(q);
		cin >> L >> R >> k;
		int ans = 0;
		for(int l = L,r = l + k - 1;r <= R;l++,r++){
			ans = max(ans,hld.dep[querylca(l,r)]);
		}
		cout << ans << '\n';
	}
}