#include<bits/stdc++.h>
using namespace std;
#define N 500010
//#define int long long
struct node{
	int next,to;
}ed[N<<1];
struct tree{
	int l,r,mi,mx;
}tr[N<<2];
int tot=1,idx,dfn[N],top[N],rev[N],siz[N],fa[N],dep[N],son[N],head[N];
inline void add(int x,int y){
	ed[++tot].next=head[x];
	ed[tot].to=y;
	head[x]=tot;
}
int pw=0;
inline void dfs1(int u,int f){
	dep[u]=dep[f]+1;
	siz[u]=1;
	fa[u]=f;
	
//	if(u==0)cout<<"qwqwqwqwqwq";
	for(int i=head[u];i;i=ed[i].next){
//		if(u==79843){
//			if(ed[head[u]].to==52566)cout<<-1;
//		}//cout<<ed[head[u]].to;
		int v=ed[i].to;
		if(v==f)continue;//if(u==79843)cout<<v<<"qwq";
	//	cout<<v<<endl;
//		if(v==79843)
		dfs1(v,u);
		siz[u]+=siz[v];
		if(siz[son[u]]<siz[v])son[u]=v;
	}
}
inline void dfs2(int x,int vt){
	dfn[x]=++idx;
	rev[idx]=x;
	top[x]=vt;
	if(son[x])dfs2(son[x],vt);
	for(int i=head[x];i;i=ed[i].next){
		int v=ed[i].to;
		if(v==fa[x]||v==son[x])continue;
		dfs2(v,v);
	}
}
inline int lca(int x,int y){
	while(top[x]^top[y]){
		if(dep[top[x]]<dep[top[y]])swap(x,y);
		x=fa[top[x]];
	}
	if(dep[x]>dep[y])swap(x,y);
	return x;
}
inline void build(int rt,int l,int r){
	tr[rt].l=l,tr[rt].r=r;
	if(l==r){
		tr[rt].mi=tr[rt].mx=dep[l];
		return;
	}
	int mid=l+r>>1;
	build(rt<<1,l,mid);
	build(rt<<1|1,mid+1,r);
	tr[rt].mi=min(tr[rt<<1].mi,tr[rt<<1|1].mi);
	tr[rt].mx=max(tr[rt<<1].mx,tr[rt<<1|1].mx);
}
inline int query_min(int rt,int l,int r){
	if(l<=tr[rt].l&&tr[rt].r<=r){
		return tr[rt].mi;
	}
	int mid=tr[rt].l+tr[rt].r>>1,minn=1145141919;
	if(l<=mid){
		minn=min(minn,query_min(rt<<1,l,r));
	}
	if(r>mid)minn=min(minn,query_min(rt<<1|1,l,r));
	return minn;
}
inline int query_max(int rt,int l,int r){
	if(l<=tr[rt].l&&tr[rt].r<=r){
		return tr[rt].mx;
	}
	int mid=tr[rt].l+tr[rt].r>>1,maxn=-1145141919;
	if(l<=mid){
		maxn=max(maxn,query_max(rt<<1,l,r));
	}
	if(r>mid){
		maxn=max(maxn,query_max(rt<<1|1,l,r));
	}
	return maxn;
}
int n,m,k[N];
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	//cout<<n;
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		k[x]++,k[y]++;
		add(x,y),add(y,x);
	//	cout<<i<<endl;
	}
//	cout<<tot;
//	cout<<ed[head[79843]].to;
	int p=0;
	for(int i=1;i<=n;i=-~i){
		if(k[i]>=3)p=1;
	}
//	cout<<p<<endl;
	dfs1(1,0);//cout<<"qwq";
	dfs2(1,1);
	build(1,1,n);//cout<<"qwq";
//	for(int i=1;i<=q;i=-~i){
//		int x,y;
//		cin>>x>>y;
//		cout<<lca(x,y)<<endl;;
//	}
	scanf("%d",&m);
	
	if(p){
	//	cout<<1;
		while(m--){
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			if(k==1){
				printf("%d\n",query_max(1,l,r));
				continue;
			}
			int qwq=0;
			for(int i=l;i<r;i=-~i){
				int lll=i;
				for(int j=i+1;j<=r;j=-~j){
					lll=lca(lll,j);
					if(j-i+1>=k){
						qwq=max(qwq,dep[lll]);
						break;
					} 
				}
				if(k==r-l+1)break;
	        }
	     //   cout<<"qwq";
	        printf("%d\n",qwq);
		}
	}
	else{
		while(m--){
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			int qwq=0;
			for(int i=l;i<=r;i=-~i){
				if(k+i-1>r)break;
				qwq=max(qwq,query_min(1,i,k+i-1));
			}
			printf("%d\n",qwq);
		}
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
