#include<bits/stdc++.h>
#define pi pair<int,int>
#define fi first
#define sec second
#define mk make_pair
using namespace std;
bool qbf;
int tot,df[1000010],ff[1000010],dfn[1000010],rk[1000010],siz[1000010],n,dep[1000010],h[1000010],cnt,Q,f[5010][5010],Log2[2000010],st2[500010][20];
pi st[2000010][22];
struct node{int s,t;}a[1000010];
void add(int x,int y){a[++cnt].s=h[x],a[cnt].t=y,h[x]=cnt;}
void dfs(int x,int fa){
	dfn[++dfn[0]]=x,siz[x]=1,rk[dfn[0]]=x;
	df[x]=++tot,dep[x]=dep[fa]+1,st[tot][0]=mk(dep[x],x),ff[x]=fa;
	for(int i=h[x];i;i=a[i].s)
		if(a[i].t!=fa){			
			st[++tot][0]=mk(dep[x],x);
			dfs(a[i].t,x);
			siz[x]+=siz[a[i].t];
		}
}
int qlca(int x,int y){
	if(df[x]>df[y])swap(x,y);
	int u=Log2[df[y]-df[x]+1];
	return min(st[df[x]][u],st[df[y]-(1<<u)+1][u]).sec;
}
int rd(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int qlca2(int l,int r){
	int u=Log2[r-l+1];
	return qlca(st2[l][u],st2[r-(1<<u)+1][u]);
}
//#define ls x<<1
//#define rs x<<1|1
//struct SGT{int l,r,lca;}tree[2000010];
//void build(int x,int l,int r){
//	tree[x].l=l,tree[x].r=r;
//	if(l==r){
//		tree[x].lca=l;
//		return;
//	}
//	int mid=(l+r)>>1;
//	build(ls,l,mid),build(rs,mid+1,r);
//	tree[x].lca=qlca(tree[ls].lca,tree[rs].lca);
//}
//int query(int x,int l,int r){
//	if(l<=tree[x].l&&tree[x].r<=r)return tree[x].lca;
//	if(tree[ls].r<l)return query(rs,l,r);
//	if(tree[rs].l>r)return query(ls,l,r);
//	return qlca(query(ls,l,r),query(rs,l,r));
//}
//#undef ls
//#undef rs
bool wtc;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
//	printf("%lf\n",(&qbf-&wtc)/1048576.0);
	n=rd();
	for(int i=1;i<=n-1;i++){
		int x=rd(),y=rd();
		add(x,y),add(y,x);
	}
	dfs(1,0);
	for(int i=2;i<=tot;i++)
		Log2[i]=Log2[i/2]+1;
	for(int j=1;j<=Log2[tot];j++)
		for(int i=1;i+(1<<j)-1<=tot;i++)
			st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
	if(n<=5000){
		for(int i=1;i<=n;i++){
			f[i][i]=i;
			for(int j=i+1;j<=n;j++)
				f[i][j]=qlca(f[i][j-1],j);
		}
		Q=rd();
		while(Q--){
			int l=rd(),r=rd(),k=rd();
			int maxn=0;
			for(int i=l;i<=r-k+1;i++)maxn=max(maxn,dep[f[i][i+k-1]]);
			printf("%d\n",maxn);	
		}
	}
	else{
		Q=rd();
		for(int i=1;i<=n;i++)st2[i][0]=i;
		for(int j=1;j<=Log2[n];j++)
			for(int i=1;i+(1<<j)-1<=n;i++)
				st2[i][j]=qlca(st2[i][j-1],st2[i+(1<<(j-1))][j-1]);
		while(Q--){
			int l=rd(),r=rd(),k=rd();
			if(k==r-l+1){
				printf("%d\n",dep[qlca2(l,r)]);
				continue;
			}
			else{
				int maxn=0;
				for(int i=l;i<=r-k+1;i+=1000){
					if(i+k-1>r)break;
					maxn=max(maxn,dep[qlca2(i,i+k-1)]);
				}
				printf("%d\n",maxn);
			}
		}
	}
}
