#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 5e5 + 5;
int st[N][20],dep[N],dfn[N],cnt,lca[N][20],du[N];
vector<int> t[N];
void dfs(int x,int fa){
	dfn[x] = ++cnt;
	st[dfn[x]][0] = fa;
	dep[x] = dep[fa] + 1;
	for(int nx : t[x])if(nx != fa){
		dfs(nx,x);
	}
}
int get(int x,int y){
	return dep[x] < dep[y] ? x : y; 
}
void pre_work(){
	for(int j=1;j<20;j++){
		for(int i=1;i + (1 << j) - 1 <= cnt;i++){
			st[i][j] = get(st[i][j - 1],st[i + (1 << j - 1)][j - 1]);
		}
	}
}
int LCA(int a,int b){
//	cout<<a<<" "<<b<<endl;
	if(a == b) return a;
	a = dfn[a],b = dfn[b];
	if(a > b) swap(a,b);
	a++;
//	cout<<a<<" "<<b<<" "<<st[a][2]<<endl;
	int k = log(b - a + 1) / log(2);
//	cout<<k<<endl;
	return get(st[a][k],st[b - (1 << k) + 1][k]);
}
int getl(int a,int b){
//	cout<<a<<" "<<b<<endl;
	int k = log(b - a + 1) / log(2);
	return LCA(lca[a][k],lca[b - (1 << k) + 1][k]); 
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	bool flagb = true,cntdu1 = 0,cntdu2 = 0;
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		du[u]++,du[v]++;
		t[u].push_back(v);
		t[v].push_back(u);
	}
	dfs(1,0);
	pre_work();
/*	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cout<<"LCA "<<i<<" "<<j<<": "<<LCA(i,j)<<endl;
		}
	}*/
	for(int i=1;i<=n;i++){
		lca[i][0] = i;
	}
	for(int j=1;j<20;j++){
		for(int i=1;i + (1 << j) - 1<= n;i++){
//			cout<<i<<" "<<j<<endl;
			lca[i][j] = LCA(lca[i][j - 1],lca[i + (1 << j - 1)][j - 1]);
		}
	}
	int q;
	cin>>q;
	while(q--){
		int l,r,k,res = 0;
		cin>>l>>r>>k;
		for(int kk = k;kk<=r - l + 1;kk++){
			for(int i=l;i + kk - 1<=r;i++){
				if(dep[getl(i,i + kk - 1)] > res){
					res = dep[getl(i,i + kk - 1)];
				}
			}
		}
		cout<<res<<'\n';
	}
	return 0;
}

