#include<bits/stdc++.h>
using namespace std;
int n, q, dep[500005], dfn[2000005], cur, pos[500005], lg[2000005];
int mn[2000005][25];
vector<int> e[500005];
struct Query{int l, r, k;} Q[500005];
void dfs(int k, int pr){
	dep[k] = dep[pr] + 1, pos[k] = ++cur, dfn[cur] = k;
	for(int i = 0; i < e[k].size(); i++) if(e[k][i] != pr) dfs(e[k][i], k), cur++, dfn[cur] = k;
}
void init(){
	for(int i = 1; i <= cur; i++) mn[i][0] = dfn[i];
	for(int i = 1; i <= lg[cur]; i++)
		for(int j = 1; j + (1 << i) - 1 <= cur; j++)
			mn[j][i] = (dep[mn[j][i - 1]] <= dep[mn[j + (1 << (i - 1))][i - 1]]) ? mn[j][i - 1] : mn[j + (1 << (i - 1))][i - 1];
}
int lca(int x, int y){ x = pos[x], y = pos[y];
	if(x > y) swap(x, y);
	int tmp = lg[y - x + 1];
	return (dep[mn[x][tmp]] <= dep[mn[y - (1 << tmp) + 1][tmp]]) ? mn[x][tmp] : mn[y - (1 << tmp) + 1][tmp];
}
namespace SubTask1{
	int d[500005][25];
	void init1(){
		for(int i = 1; i <= n; i++) d[i][0] = i;
		for(int i = 1; i <= lg[n]; i++)
			for(int j = 1; j + (1 << i) - 1 <= n; j++)
				d[j][i] = lca(d[j][i - 1], d[j + (1 << (i - 1))][i - 1]);
	}
	int qry(int x, int y){
		if(x > y) swap(x, y); int tmp = lg[y - x + 1];
		return lca(d[x][tmp], d[y - (1 << tmp) + 1][tmp]);
	}void solve(){ init1();
		for(int i = 1; i <= q; i++)
			cout << dep[qry(Q[i].l, Q[i].r)] << '\n';
		return ;
	}
}
namespace SubTask2{
	int pre[5005][5005];
	void solve(){
		for(int i = 1; i <= n; i++){
			pre[i][i] = i;
			for(int j = i + 1; j <= n; j++) pre[i][j] = lca(pre[i][j - 1], j);
		}
		for(int i = 1; i <= q; i++){
			int ans = 1;
			for(int j = Q[i].l; j + Q[i].k - 1 <= Q[i].r; j++) ans = max(ans, dep[pre[j][j + Q[i].k - 1]]);
			cout << ans << '\n';
		}
	}
}
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n; for(int i = 1, u, v; i < n; i++) cin >> u >> v, e[u].push_back(v), e[v].push_back(u);
	for(int i = 2; i <= 2000000; i++) lg[i] = lg[i >> 1] + 1;
	dfs(1, 0), init(); bool flag = true; cin >> q;
	for(int i = 1; i <= q; i++) cin >> Q[i].l >> Q[i].r >> Q[i].k, flag &= (Q[i].k == Q[i].r - Q[i].l + 1);
	if(flag){SubTask1::solve(); return 0;}
	if(n <= 5000){SubTask2::solve(); return 0;}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
