#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define rg register
#define fo(i,l,r) for(rg int i(l);i<=(r);++i)
#define rp(i,r,l) for(rg int i(r);i>=(l);--i)
#define pb push_back
#define pc putchar
#define gc getchar
using namespace std;
inline int re() {
	rg int x=0,p=1;rg char c=gc();
	while(!isdigit(c)) {
		if(c=='-') p=-1;
		c=gc();
	}
	while(isdigit(c)) (x*=10)+=c-48,c=gc();
	return x*p;
}
inline void wt(rg int x) {
	if(x<0) pc('-'),x=-x;
	if(x>9) wt(x/10);
	pc(x%10+48);
}

const int N=5e5+5;

int n,q;
int tot,final[N],nt[N<<1],to[N<<1],dfn[N],dfc;
int fa[N][20],sz[N],is[N],dep[N];
int ql[N],qr[N],qk[N];

void link(int x,int y) {
	to[++tot]=y;
	nt[tot]=final[x];
	final[x]=tot;
}
void dfs(int x,int f) {
	dep[x]=dep[f]+1;
	sz[x]=1;
	fa[x][0]=f;
	fo(i,1,19) fa[x][i]=fa[fa[x][i-1]][i-1];
	dfn[x]=++dfc;
	is[dfc]=x;
	for(int i=final[x];i;i=nt[i]) {
		int y=to[i];
		if(y!=f) {
			dfs(y,x);
			sz[x]+=sz[y];
		}
	}
}
int lca(int x,int y) {
	if(dep[x]<dep[y]) swap(x,y);
	rp(i,19,0) if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
	if(x==y) return x;
//	printf("%d %d\n",x,y);
	rp(i,19,0) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}

namespace brute {
	int mn[5005][5005],mx[5005][5005],lca[5005][5005],ls[N];
	void Main() {
		fo(i,1,n) {
			mn[i][i]=mx[i][i]=i;
			fo(j,i+1,n) {
				mn[i][j]=mn[i][j-1];
				mx[i][j]=mx[i][j-1];
				if(dfn[j]<dfn[mn[i][j]]) mn[i][j]=j;
				if(dfn[j]>dfn[mx[i][j]]) mx[i][j]=j;
			}
		}
		fo(i,1,n) {
			int l=dfn[i],r=dfn[i]+sz[i]-1;
			for(int u=final[i];u;u=nt[u]) {
				int j=to[u];
				fo(x,dfn[j],dfn[j]+sz[j]-1) {
					fo(y,dfn[j]+sz[j],r) lca[is[x]][is[y]]=lca[is[y]][is[x]]=i;
				}
			}
			fo(j,dfn[i],dfn[i]+sz[i]-1) {
				lca[i][is[j]]=lca[is[j]][i]=i;
			}
		}
		fo(i,1,q) {
			int l=ql[i],r=qr[i],k=qk[i];
			int ans=0;
			fo(i,l,r-k+1) {
				int j=i+k-1;
				int x=mn[i][j],y=mx[i][j];
				ans=max(ans,dep[lca[x][y]]);
//				printf("%d %d ",x,y);
//				printf("%d ",lca[x][y]);
			}
			printf("%d\n",ans);
		}
	}
}
namespace B {
	int lgg[N];
	struct pr {
		int x,i;
	}mn[N][20],mx[N][20];
	bool operator<(pr a,pr b) {
		return a.x<b.x;
	}
	void Main() {
		fo(i,2,500000) lgg[i]=lgg[i/2]+1;
		fo(i,1,n) {
			mn[i][0]=mx[i][0]={dfn[i],i};
		}
		fo(j,1,19) {
			fo(i,1,n-(1<<j)+1) {
				mn[i][j]=min(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
				mx[i][j]=max(mx[i][j-1],mx[i+(1<<j-1)][j-1]);
			}
		}
//		fo(i,1,n) {
//			fo(j,1,n) {
//				printf("%d %d : %d\n",i,j,lca(i,j));
//			}
//		}
		fo(i,1,q) {
			int l=ql[i],r=qr[i];
			int s=lgg[r-l+1];
			int x=min(mn[l][s],mn[r-(1<<s)+1][s]).i;
			int y=max(mx[l][s],mx[r-(1<<s)+1][s]).i;
//			printf("%d %d %d ",x,y,lca(x,y));
//			int lc=lca(x,y);
//			printf("[ %d %d ] %d %d ",dfn[lc],dfn[lc]+sz[lc]-1,dfn[x],dfn[y]);
			printf("%d\n",dep[lca(x,y)]);
		}
	}
}
namespace A {
	void Main() {
		fo(i,1,q) {
			puts("1");
		}
	}
}
bool pdB() {
	fo(i,1,q) {
		if(qk[i]!=qr[i]-ql[i]+1) return 0;
	}
	return 1;
}
bool pdA() {
	return 1;
}

int main() {
//	system("fc query.out queryb.out");return 0;
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=re();
	fo(i,1,n-1) {
		int x=re(),y=re();
		link(x,y),link(y,x);
	}
	dfs(1,0);
	q=re();
	fo(i,1,q) ql[i]=re(),qr[i]=re(),qk[i]=re();
	if(n<=5000&&q<=5000) {
		brute::Main();
		return 0;
	}
	if(pdB()) {
		B::Main();
		return 0;
	}
	if(pdA()) {
		A::Main();
		return 0;
	}
}
