#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>g[500010];
int x,y;
int fa[500010][30];
int dep[500010];
int st[2000010][30];
int vis[500010];
void bfs(){
	queue<int>q;
	vis[1]=1;
	q.push(1);
	dep[1]=1;
	fa[1][0]=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(auto v:g[u]){
			if(vis[v])continue;
			dep[v]=dep[u]+1;
			fa[v][0]=u;
			vis[v]=1;
			q.push(v);
		}
	}
}
int lca(int x,int y){
//	cout<<"lca "<<x<<" "<<y<<"=";
	if(x==0||y==0)return 1;
	if(dep[x]>dep[y])swap(x,y);
	int z=dep[y]-dep[x];
	for(int i=20;i>=0;i--){
		if(z&(1<<i)){
			y=fa[y][i];
		}
	}
	if(x==y){
//		cout<<x<<"\n";
		return x;
	}
	for(int i=20;i>=0;i--){
		if(fa[x][i]!=fa[y][i]&&fa[x][i]!=0){
			x=fa[x][i];
			y=fa[y][i];
		}
	}
//	cout<<fa[x][0]<<"\n";
	return fa[x][0];
}
int lb(int x){
	return x&(-x);
}
int hb(int x){
	while(x!=x&(-x)){
		x-=x&(-x);
	}
	return x;
}
int ct(int x){
	int res=0;
	while(x){
		res++;
		x>>=1;
	}
	return res-1;
}
int q,l,r,k;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n-1;i++){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	bfs();
//	cout<<"bfs\n";
	for(int j=1;j<=20;j++){
		for(int i=1;i<=n;i++){
			fa[i][j]=fa[fa[i][j-1]][j-1];
//			cout<<fa[i][j]<<" ";
		}
//		cout<<"\n";
	}
//	cout<<"bz\n";
	for(int i=1;i<=n;i++)st[i][0]=i;
	for(int j=1;j<=20;j++){
		for(int i=1;i<=n;i++){
			st[i][j]=lca(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
//		cout<<"st"<<j<<"\n";
	}
//	cout<<"ycl\n";
	int q,l,r,k;
	cin>>q;
	int ans,ca;
	while(q--){
		cin>>l>>r>>k;
		ans=0;
		int yy=ct(hb(k));
		for(int i=l;i<=r-k+1;i++){
			ca=lca(st[i][yy],st[i+k-(1<<yy)][yy]);
			ans=max(ans,dep[ca]);
		}
		cout<<ans<<"\n";
	}
}
//11:20 O(nlognlogn+qnlogn)=O(qnlogn) or nlognlogn+q(\sum r-k-l)logn might 20~64pts expect 32pts
//xingzhiA:O(qnlogn)->O(xuanxue) (16pts+[0,16]pts)
//xingzhiB: qnlogn->qlogn O(nlognlogn+qnlogn)->O(nlognlogn+qlogn) (12pts)
//sto AKer wsy will gain 100pts here (if he do not fake) orz
//wsy is shine,thanks wsy
