#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<ctime>
#include<random>
using namespace std;
namespace io{
const int BFSZ=1<<22;
char rbuffer[BFSZ+5];
int rpt,rsz;
char gc()
{
	if(rpt>=rsz)
	{
		rsz=fread(rbuffer,sizeof(char),BFSZ,stdin);
		if(rsz==0)
		{
			return EOF;
		}
		rpt=0;
	}
	return rbuffer[rpt++];
}
template<typename T>
void read(T &x)
{
	x=0;
	int f=1;
	char c=gc();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		{
			f=-1;
		}
		c=gc();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+int(c-'0');
		c=gc();
	}
	x*=f;
}
template<typename T>
void write(T x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>=10)
	{
		write(x/10);
	}
	putchar('0'+int(x%10));
}}
namespace cyrxdzj{
//#define debug
//#define check_memory
#ifdef check_memory
bool check_memory_st;
#endif
const int MAXN=6e5,MAXF=21;
const long long SUM_OP_CNT_LMT=1e8+2e7;
int n,qrycnt;
struct Qry
{
	int l,r;
	int len;
	int id;
}qry[MAXN+5];
int ans[MAXN+5];
long long sum_op_cnt;
struct Edge
{
	int to,next;
}edge[MAXN*2+5];
int edge_cnt;
int head[MAXN+5];
int fa[MAXN+5],dep[MAXN+5];
int dfnl[MAXN+5],dfnr[MAXN+5],nid[MAXN+5],nowdfn;
int dfn_lca[MAXF+2][MAXN*2+5],dfn_lca_cnt;
int dfn_appear[MAXN+5];
int lg[MAXN*2+5];
int st_lca_range[MAXF+2][MAXN+5];
vector<int>nxt_updates[MAXN+5];
struct Tree
{
	int lc,rc;
	int l,r;
	int mx;
}tree[MAXN*2+5];
int pcnt=1;
void update(int o)
{
	int lc=tree[o].lc,rc=tree[o].rc;
	tree[o].mx=max(tree[lc].mx,tree[rc].mx);
}
void handle(int o,int val)
{
	tree[o].mx=val;
}
void build(int o,int l,int r)
{
	tree[o].l=l;
	tree[o].r=r;
	if(l==r)
	{
		return;
	}
	int mid=(tree[o].l+tree[o].r)>>1;
	tree[o].lc=++pcnt;
	tree[o].rc=++pcnt;
	build(tree[o].lc,l,mid);
	build(tree[o].rc,mid+1,r);
}
void change(int o,int x,int val)
{
	if(tree[o].l==x&&tree[o].r==x)
	{
		handle(o,val);
		return;
	}
	int lc=tree[o].lc,rc=tree[o].rc;
	int mid=(tree[o].l+tree[o].r)>>1;
	if(mid>=x)
	{
		change(lc,x,val);
	}
	else
	{
		change(rc,x,val);
	}
	update(o);
}
int query(int o,int l,int r)
{
	if(tree[o].l==l&&tree[o].r==r)
	{
		return tree[o].mx;
	}
	int lc=tree[o].lc,rc=tree[o].rc;
	int mid=(tree[o].l+tree[o].r)>>1;
	if(mid>=r)
	{
		return query(lc,l,r);
	}
	else if(mid<l)
	{
		return query(rc,l,r);
	}
	else
	{
		return max(query(lc,l,mid),query(rc,mid+1,r));
	}
}
#ifdef check_memory
bool check_memory_ed;
#endif
void add_edge(int u,int v)
{
	edge[++edge_cnt]=(Edge){v,head[u]};
	head[u]=edge_cnt;
}
void pre(int u)
{
	dep[u]=dep[fa[u]]+1;
	dfnl[u]=dfnr[u]=++nowdfn;
	nid[dfnl[u]]=u;
	dfn_lca[0][++dfn_lca_cnt]=dfnl[u];
	dfn_appear[dfnl[u]]=dfn_lca_cnt;
	for(int i=head[u];i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==fa[u])
		{
			continue;
		}
		fa[v]=u;
		pre(v);
		dfnr[u]=dfnr[v];
		dfn_lca[0][++dfn_lca_cnt]=dfnl[u];
	}
}
int lca(int u,int v)
{
	if(dfnl[u]>dfnl[v])
	{
		swap(u,v);
	}
	int du=dfnl[u],dv=dfnl[v];
	int l=dfn_appear[du],r=dfn_appear[dv];
	int s=lg[r-l+1];
	#ifdef debug_
	printf("u %d v %d du %d dv %d l %d r %d\n",u,v,du,dv,l,r);
	#endif
	int df=min(dfn_lca[s][l],dfn_lca[s][r-(1<<s)+1]);
	return nid[df];
}
int lca_range(int l,int r)
{
	int s=lg[r-l+1];
	return lca(st_lca_range[s][l],st_lca_range[s][r-(1<<s)+1]);
}
void build_st()
{
	for(int i=2;i<=dfn_lca_cnt;i++)
	{
		lg[i]=lg[i>>1]+1;
	}
	for(int j=1;j<=MAXF;j++)
	{
		for(int i=1;i+(1<<(j-1))<=dfn_lca_cnt;i++)
		{
			dfn_lca[j][i]=min(dfn_lca[j-1][i],dfn_lca[j-1][i+(1<<(j-1))]);
		}
	}
	for(int i=1;i<=n;i++)
	{
		st_lca_range[0][i]=i;
	}
	for(int j=1;j<=MAXF;j++)
	{
		for(int i=1;i+(1<<(j-1))<=n;i++)
		{
			st_lca_range[j][i]=lca(st_lca_range[j-1][i],st_lca_range[j-1][i+(1<<(j-1))]);
		}
	}
}
int main()
{
	#ifdef check_memory
	printf("check_memory %lf\n",((double)((&check_memory_st)-(&check_memory_ed)))/1024/1024);
	#endif
	freopen("query.in","r",stdin);
	#ifndef debug
	freopen("query.out","w",stdout);
	#endif
	io::read(n);
	for(int i=1,u,v;i<n;i++)
	{
		io::read(u);
		io::read(v);
		add_edge(u,v);
		add_edge(v,u);
	}
	pre(1);
	build_st();
	build(1,1,n);
	#ifdef debug_
	for(int i=1;i<=dfn_lca_cnt;i++)
	{
		printf("%d ",dfn_lca[0][i]);
	}
	printf("\n");
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			printf("%d %d f %d\n",i,j,lca(i,j));
		}
	}
	#endif
	io::read(qrycnt);
	for(int i=1;i<=qrycnt;i++)
	{
		io::read(qry[i].l);
		io::read(qry[i].r);
		io::read(qry[i].len);
		qry[i].id=i;
		sum_op_cnt+=qry[i].r-qry[i].l+1-qry[i].len+1;
	}
	if(sum_op_cnt<=SUM_OP_CNT_LMT)
	//if(false)
	{
		for(int qid=1;qid<=qrycnt;qid++)
		{
			for(int r=qry[qid].l+qry[qid].len-1;r<=qry[qid].r;r++)
			{
				int l=r-qry[qid].len+1;
				ans[qry[qid].id]=max(ans[qry[qid].id],dep[lca_range(l,r)]);
			}
		}
	}
	/*else
	{
		mt19937 myrand=mt19937(time(0));
		for(int qid=1;qid<=qrycnt;qid++)
		{
			long long this_op_cnt=qry[qid].r-qry[qid].l+1-qry[qid].len+1;
			if(this_op_cnt<=100)
			{
				for(int r=qry[qid].l+qry[qid].len-1;r<=qry[qid].r;r++)
				{
					int l=r-qry[qid].len+1;
					ans[qry[qid].id]=max(ans[qry[qid].id],dep[lca_range(l,r)]);
				}
			}
			else
			{
				long long get_op_cnt=max(SUM_OP_CNT_LMT*this_op_cnt/sum_op_cnt,100ll);
				for(int i=1;i<=get_op_cnt;i++)
				{
					int r=qry[qid].l+qry[qid].len-1+(myrand()%this_op_cnt);
					int l=r-qry[qid].len+1;
					ans[qry[qid].id]=max(ans[qry[qid].id],dep[lca_range(l,r)]);
				}
			}
		}
	}*/
	else
	{
		for(int i=1;i<=n;i++)
		{
			nxt_updates[1].push_back(i);
		}
		sort(qry+1,qry+1+qrycnt,[](Qry a,Qry b){return a.len<b.len;});
		for(int now_len=1,nowq=1;(now_len<=n)&&(nowq<=qrycnt);now_len++)
		{
			for(int r:nxt_updates[now_len])
			{
				int f=lca_range(r-now_len+1,r);
				change(1,r,dep[f]);
				int nxt_update=0;
				int left=now_len+1,right=r;
				while(left<=right)
				{
					int mid=(left+right)>>1;
					if(lca_range(r-mid+1,r)!=f)
					{
						nxt_update=mid;
						right=mid-1;
					}
					else
					{
						left=mid+1;
					}
				}
				if(nxt_update)
				{
					#ifdef debug_
					printf("%d now_len %d nxt_update %d\n",r,now_len,nxt_update);
					#endif
					nxt_updates[nxt_update].push_back(r);
				}
			}
			nxt_updates[now_len].clear();
			nxt_updates[now_len].shrink_to_fit();
			while((nowq<=qrycnt)&&(qry[nowq].len==now_len))
			{
				ans[qry[nowq].id]=query(1,qry[nowq].l+now_len-1,qry[nowq].r);
				nowq++;
			}
			#ifdef debug
			if(now_len%100==0)
			{
				printf("now_len %d\n",now_len);
			}
			#endif
		}
	}
	for(int i=1;i<=qrycnt;i++)
	{
		io::write(ans[i]);
		putchar('\n');
	}
	return 0;
}}
int main()
{
	return cyrxdzj::main();
}
