#include <algorithm>
#include <iostream>
#include <cstring>
#include <utility>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#define fi first
#define se second
#define mod 1000000007
using namespace std;
typedef long long ll;
const int N = 500005;vector<int> to[N];
int n, q, _c, Lg[N], df[N], ft[20][N], sg[20][N], de[N];
inline int mnd(int x, int y){return de[x] == de[y] ? min(x, y) : de[x] < de[y] ? x : y;}
void dfs(int u, int fa){ft[0][++ _c] = fa, df[u] = _c;
	for (int v : to[u]) if (v != fa) de[v] = de[u] + 1, dfs(v, u);
}
inline int lca(int x, int y){
	if (x == y) return x;x = df[x], y = df[y];
	if (x > y) swap(x, y);x ++;int k = Lg[y - x];
	return mnd(ft[k][x], ft[k][y - (1 << k) + 1]);
}
inline int qry(int l, int r){int k = Lg[r - l];
return lca(sg[k][l], sg[k][r - (1 << k) + 1]);}
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 = 2;i <= n;i ++) Lg[i] = Lg[i >> 1] + 1;
	for (int i = 1, u, v;i < n;i ++) cin >> u >> v,
	to[u].push_back(v), to[v].push_back(u);
	cin >> q, de[1] = 1, dfs(1, 0);
	for (int i = 1;i <= Lg[n];i ++)
	for (int j = 1;j + (1 << i) - 1 <= n;j ++)
	ft[i][j] = mnd(ft[i - 1][j], ft[i - 1][j + (1 << i - 1)]);
	for (int i = 1;i <= n;i ++) sg[0][i] = i;
	for (int i = 1;i <= Lg[n];i ++)
	for (int j = 1;j + (1 << i) - 1 <= n;j ++)
	sg[i][j] = lca(sg[i - 1][j], sg[i - 1][j + (1 << i - 1)]);
	for (int l, r, k, ans;q --;){
		cin >> l >> r >> k, ans = 0;
		for (int i = l;i + k - 1 <= r;i ++)
		ans = max(ans, de[qry(i, i + k - 1)]);
		cout << ans << '\n';
	}
}
