#include <bits/stdc++.h>
#define ll long long
using namespace std;
int read(){
	int t1=0,t2=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')t2=-1;
		c=getchar();
	}while(c>='0'&&c<='9')t1=t1*10+c-'0',c=getchar();
	return t1*t2;
}
const int N=200001,M=64;
int n,q,t,h[N],idx=0,f[N][M],dep[N],cnt=0;
bool vis[N];
struct node{
	int to,next;
}ed[N];
void build(int u,int v){
	ed[++idx].to=v;
	ed[idx].next=h[u];
	h[u]=idx;
}
void depthbfs(){
	queue<int> niko;niko.push(1);dep[1]=1;
	while(!niko.empty()){
		int now=niko.front();niko.pop();
		vis[now]=1;
		for(int i=h[now];i;i=ed[i].next){
			int v=ed[i].to;
			if(vis[v])continue;
			f[v][0]=now;
			for(int j=1;j<=t;j++){
				f[v][j]=f[f[v][j-1]][j-1];
			}
			dep[v]=dep[now]+1;niko.push(v);
		}
	}
}
int LCA(int x,int y){
	if(dep[x]>dep[y])swap(x,y);
	for(int j=t;j>=0;j--){
		if(dep[f[y][j]]>=dep[x]){
			y=f[y][j];
		}
	}
	if(x==y)return x;
	for(int j=t;j>=0;j--){
		if(f[y][j]!=f[x][j])y=f[y][j],x=f[x][j];
	}
	return f[x][0];
}
int specialLCA(int l,int r){
	if(r-l==1){
		return LCA(l,r);
	}else if(r-l==0)return l;
	int mid=(l+r)/2;
	int t1=specialLCA(l,mid),t2=specialLCA(mid+1,r);
	return LCA(t1,t2);
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();t=(int)log2(n)-1;
	for(int i=1;i<=n-1;i++){
		int u,v;u=read();v=read();
		build(u,v);
		build(v,u);
	}
	depthbfs();
	q=read();
	for(int i=1;i<=q;i++){
		int l,r,k;l=read();r=read();k=read();
		if(k==r-l+1){
			cout<<dep[specialLCA(l,r)]<<endl; 
		}
		else{
			int ans=0;
			for(int i=k;i<=r-l+1;i++){
				for(int j=l,q=j+i-1;q<=r;j++,q++){
					ans=max(ans,dep[specialLCA(j,q)]);
				}
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}
