#include<bits/stdc++.h>
using namespace std;typedef long long ll;
int read(){int x=0,f=1;char ch;for(;!isdigit(ch=getchar());)if(ch=='-')f=-1;for(;isdigit(ch);ch=getchar())x=x*10+(ch-'0');return x*f;}
namespace Main
{
	const int N=500010;int n,m,q,k,Log[N],fa[N],sz[N],id[N],st[19][N],head[N],to[N<<1],nxt[N<<1],dep[N],Fa[N][19],tot,x,y,z,xx,yy,zz,ans[N];struct nd{int x,y,z;}b[N<<1];vector<nd>e[N];bool operator<(nd x,nd y){return x.y>y.y;}void link(int x,int y){to[++tot]=y,nxt[tot]=head[x],head[x]=tot;}int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
	void dfs0(int x){dep[x]=dep[Fa[x][0]]+1;for(int i=1;i<19;++i)Fa[x][i]=Fa[Fa[x][i-1]][i-1];for(int i=head[x];i;i=nxt[i])if(to[i]!=Fa[x][0])Fa[to[i]][0]=x,dfs0(to[i]);}int LCA(int x,int y){if(dep[x]<dep[y])swap(x,y);for(int i=19;i--;)if(dep[Fa[x][i]]>=dep[y])x=Fa[x][i];if(x==y)return x;for(int i=19;i--;)if(Fa[x][i]!=Fa[y][i])x=Fa[x][i],y=Fa[y][i];return Fa[x][0];}
	int qry(int x,int y){return min(st[Log[y-x]][x],st[Log[y-x]][y-(1<<Log[y-x])]);}bool cmp(int x,int y){return st[0][x]>st[0][y];}
	namespace sgt{int v[N<<2];void upd(int k,int l,int r,int p,int z){v[k]=max(v[k],z);if(l<r){int mid=(l+r)>>1;(p<=mid?upd(k<<1,l,mid,p,z):upd(k<<1|1,mid+1,r,p,z));}}int qry(int k,int l,int r,int L,int R){if(L<=l&&r<=R)return v[k];int mid=(l+r)>>1;return max((L<=mid?qry(k<<1,l,mid,L,R):0),(mid<R?qry(k<<1|1,mid+1,r,L,R):0));}}
	void main()
	{
		ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cin>>n,m=n,Log[0]=-1;for(int i=1;i<=n;++i)Log[i]=Log[i>>1]+1,fa[i]=i,sz[i]=1;for(int i=n;--i;)cin>>x>>y,link(x,y),link(y,x);dfs0(1);for(int i=1;i<n;++i)st[0][i]=dep[LCA(i,i+1)],id[i]=i;for(int i=1;i<19;++i)for(int j=1;j+(1<<i)<=n;++j)st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
		for(int i=1;i<=n;++i)b[i]=(nd){i,1,dep[i]};sort(id+1,id+n,cmp);for(int i=1;i<n;++i)x=id[i],y=find(x+1),x=find(x),fa[y]=x,sz[x]+=sz[y],b[++m]=(nd){x,sz[x],st[0][id[i]]};sort(b+1,b+m+1);/*for(int i=1;i<=m;++i)printf("#%d %d %d\n",b[i].x,b[i].y,b[i].z);*/
		cin>>q;for(int i=1;i<=q;++i)cin>>x>>y>>k,ans[i]=(k==1?0:qry(x,x+k-1)),e[k].emplace_back((nd){x,y-k+1,i});
		for(int i=n,j=1;i;--i){for(;j<=m&&b[j].y==i;++j)sgt::upd(1,1,n,b[j].x,b[j].z);for(int l=0,I=(int)e[i].size();l<I;++l)ans[e[i][l].z]=max(ans[e[i][l].z],sgt::qry(1,1,n,e[i][l].x,e[i][l].y));}
		for(int i=1;i<=q;++i)cout<<ans[i]<<'\n';
	}
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	Main::main();
	return 0;
}
