# include<bits/stdc++.h>
# define int long long
using namespace std;

int n,q,x,y,dep[100005],st[100005][25],lca[505][505],l,r,k,cur,ans;
vector<int> v[100005];
void dfs(int cur,int fa) {
	dep[cur] = dep[fa]+1;
	st[cur][0] = fa;
	int sz = v[cur].size();
	for (int i = 0;i < sz;i++) {
		int nx = v[cur][i];
		if (nx == fa) continue;
		dfs(nx,cur);
	} 
}
int getlca(int x,int y) {
	if (dep[x] > dep[y]) swap(x,y);
	for (int i = 20;i >= 0;i--) {
		if (dep[st[y][i]] >= dep[x]) y = st[y][i];
	}
	if (x == y) return x;
	for (int i = 20;i >= 0;i--) {
		if (st[x][i] != st[y][i]) x = st[x][i],y = st[y][i];
	}
	if (x == y) return x;
	else return st[x][0];
}
signed main()  {
	//freopen("query2.in","r",stdin);
	//freopen("out.txt","w",stdout);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin >> n;
	for (int i = 1;i < n;i++) {
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0);
	for (int i = 1;i <= 20;i++) {
		for (int j = 1;j <= n;j++) {
			st[j][i] = st[st[j][i-1]][i-1];
		}
	}
	for (int i = 1;i <= n;i++) {
		lca[i][i] = i;
		for (int j = i+1;j <= n;j++) {
			lca[i][j] = getlca(i,j);
			lca[j][i] = lca[i][j];
		}
	}
	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= n;j++) {
		//	cout << "lca:" << i << ' ' << j << ' ' << lca[i][j] << endl;
		}
	}
	cin >> q;
	while (q--) {
		cin >> l >> r >> k;
		ans = 0;
		for (int i = l;i+k-1 <= r;i++) {
			cur = i;
			for (int j = i;j <= i+k-1;j++) {
				cur = lca[cur][j];
			}
			//cout << "check:" << i << ' ' << k << ' ' << cur << endl; 
			ans = max(ans,dep[cur]);
		}
		cout << ans << endl;
	}
	
	return 0;
}
