#include<bits/stdc++.h>
#define ll long long
#define ci const int
#define ls (x<<1)
#define rs ((x<<1)|1)
#define mid ((l+r)>>1)
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
using namespace std;
inline ll read(){ll u,f=1;char o;while((o=getchar())<48||o>57)if(o=='-')f=-1;u=(o^48);while((o=getchar())>=48&&o<=57)u=(u<<1)+(u<<3)+(o^48);return u*f;}
bool ST;
ci N=1e6+5,M=5e3+5,mod=1e9+7;
ll n,m,q;
vector<int>w[N];
void add(int x,int y)
{
	w[x].push_back(y);
	w[y].push_back(x);
}
int dfn[N],ceng[N],dfstime;
int book[M][M],use[M][M];
vector<int>a[M];
void dfs(int x,int cc)
{
	dfn[x]=++dfstime;ceng[x]=cc;
	for(auto d:w[x])if(!dfn[d])
	{
		dfs(d,cc+1);
		for(auto e:a[d])a[x].push_back(e),book[e][x]=book[x][e]=x;
	}
	a[x].push_back(x);book[x][x]=x;
	for(auto d:w[x])for(auto e:w[x])if(d!=e)
	{
		for(auto dd:a[d])for(auto ee:a[e])book[dd][ee]=x;
	}
}
/*namespace solve2
{
	struct node
	{
		int l,r,k,id;
	}ask[N],ask2[N];
	int ans[N];
	void dfs3(int x,int cc)
	{
		ceng[x]=cc;
		for(auto d:w[x])if(!ceng[d])
		{
			dfs3(d,cc+1);
		}
	}
	int maxn[N],suml[N],sumr[N];
	int lim;
	void build(int x,int l,int r)
	{
		if(l==r)
		{
			maxn[x]=suml[x]=sumr[x]=(ceng[l]>=lim);
			return;
		}
		build(ls,l,mid);
		build(rs,mid+1,r);
		maxn[x]=max(maxn[ls],max(maxn[rs],suml[rs]+sumr[ls]));
		suml[x]=suml[ls];
		if(suml[ls]==mid-l+1)suml[x]+=suml[rs];
		sumr[x]=sumr[rs];
		if(sumr[rs]==r-mid)sumr[x]+=sumr[ls];
	}
	int maxn1,sumr1;
	void cha(int x,int l,int r,int o,int o1)
	{
		if(o<=l&&r<=o1)
		{
			maxn1=max(maxn1,max(maxn[x],sumr1+suml[x]));
			if(sumr[x]==r-l+1)sumr1+=sumr[x];
			else sumr1=sumr[x];
			return;
		}
		if(r<o||o1<l)return;
		cha(ls,l,mid,o,o1);
		cha(rs,mid+1,r,o,o1);
	}
	void cha1(int LL,int RR,int ansl,int ansr)
	{
		if(LL>RR)return;
		if(ansl==ansr)
		{
			fo(i,LL,RR)
			{
				ans[ask[i].id]=ansl;
			}
			return;
		}
		build(1,1,n);
		lim=((ansl+ansr)>>1);
		int j=LL,k=RR;
		fo(i,LL,RR)
		{
			maxn1=sumr1=0;
			cha(1,1,n,ask[i].l,ask[i].r);
			if(maxn1>=ask[i].k)ask2[j]=ask[i],++j;
			else ask2[k]=ask[i],--k;
		}
		fo(i,LL,RR)ask[i]=ask2[i];
		cha1(LL,k,ansl,((ansl+ansr)>>1)),cha1(k+1,RR,((ansl+ansr)>>1)+1,ansr);
	}
	int main()
	{
		dfs3(1,1);
		q=read();
		fo(i,1,q)
		{
			int l=read(),r=read(),k=read();
			ask[i]={l,r,k,i};
		}
		cha1(1,q,1,n);
		fo(i,1,q)
		{
			cout<<ans[i]<<'\n';
		}
		return 0;
	}
}*/
namespace solve
{
	int lca[N][20],seg[N];
	void dfs2(int x,int cc)
	{
		seg[dfn[x]=++dfstime]=x;ceng[x]=cc;
		for(auto d:w[x])if(!dfn[d])
		{
			int s=0;
			lca[d][0]=x;
			while(lca[lca[d][s]][s])
			{
				lca[d][s+1]=lca[lca[d][s]][s];
				++s;
			}
			dfs2(d,cc+1);
		}
	}
	int maxn[20][N],minn[20][N];
	int cha(int l,int r)
	{
		int w=log2(r-l+1);
		return max(maxn[w][l],maxn[w][r-(1<<w)+1]);
	}
	int cha2(int l,int r)
	{
		int w=log2(r-l+1);
		return min(minn[w][l],minn[w][r-(1<<w)+1]);
	}
	int find(int x,int y)
	{
		if(ceng[x]<ceng[y])swap(x,y);
		fd(i,19,0)if(ceng[lca[x][i]]>=ceng[y])x=lca[x][i];
		fd(i,19,0)if(lca[x][i]!=lca[y][i])x=lca[x][i],y=lca[y][i];
		if(x!=y)x=lca[x][0];
		return x;
	}
	int main()
	{
	/*	bool F=0;
		if(w[1].size()!=1)F=1;
		fo(i,2,n)
		{
			if(w[i].size()>2)F=1;
		}
		if(!F)
		{
			return solve2::main();
		}*/
		dfs2(1,1);
		fo(i,1,n)maxn[0][i]=dfn[i],minn[0][i]=dfn[i];
		fo(j,1,19)fo(i,1,n-(1<<j)+1)
		{
			maxn[j][i]=max(maxn[j-1][i],maxn[j-1][i+(1<<(j-1))]);
			minn[j][i]=min(minn[j-1][i],minn[j-1][i+(1<<(j-1))]);
		}
		q=read();
		while(q--)
		{
			int l=read(),r=read();ll k=read();
			int ans=0;
			fo(i,l,r-k+1)
			{
				int x=seg[cha(i,i+k-1)],y=seg[cha2(i,i+k-1)];
				ans=max(ans,ceng[find(x,y)]);
			}
			cout<<ans<<'\n';
		}
		return 0;
	}
}
bool ED;
int main()
{cerr<<(&ST-&ED)/1048576.0<<'\n';
//	freopen("query2.in","r",stdin);
//	freopen("1.ans","w",stdout);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int T=1;
	while(T--)
	{
		n=read();
		fo(i,1,n-1)
		{
			int u=read(),v=read();
			add(u,v);
		}
		if(n<=5000)
		{
			dfs(1,1);
			fo(i,1,n)
			{
				use[i][i]=i;
				fo(j,i+1,n)use[i][j]=book[use[i][j-1]][j];
			}
			q=read();
			while(q--)
			{
				int l=read(),r=read();ll k=read();
				int ans=0;
				fo(i,l,r-k+1)
				{
					ans=max(ans,ceng[use[i][i+k-1]]);
				}
				cout<<ans<<'\n';
			}
		}
		else return solve::main();
	}
}
