#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
int n,q;
struct Edge
{
	int pre,v;
}e[maxn<<1];
int last[maxn],g;
void add(int u,int v)
{
	e[++g]={last[u],v};
	last[u]=g;
}
int R[maxn][25],R1[maxn][25];
int dfn[maxn],fa[maxn],dep[maxn];
int lg[maxn];
int dfn1[maxn];
void st()
{
	for(int i=1;i<=n;i++)R[i][0]=dep[dfn1[i]],R1[i][0]=i;
	for(int i=1;i<=20;i++)
	{
		for(int j=1;j+(1<<i-1)-1<=n;j++)
		{
			if(R[j][i-1]<R[j+(1<<i-1)][i-1])R[j][i]=R[j][i-1],R1[j][i]=R1[j][i-1];
			else R[j][i]=R[j+(1<<i-1)][i-1],R1[j][i]=R1[j+(1<<i-1)][i-1];
		}
	}
}
int get_lca(int l,int r)
{
	l=dfn[l],r=dfn[r];
	if(l>r)swap(l,r);
	int len=r-l+1;
	int p=R1[l][lg[len]];
	if(R[l][lg[len]]>=R[r-(1<<lg[len])+1][lg[len]])p=R1[r-(1<<lg[len])+1][lg[len]];
	if(p==l)return dfn1[l];
	return fa[dfn1[p]];
}
int cnt;
void dfs(int u,int f)
{
	dfn[u]=++cnt;
	dfn1[cnt]=u;
	fa[u]=f;
	dep[u]=dep[f]+1;
	for(int i=last[u];i;i=e[i].pre)
	{
		int v=e[i].v;
		if(v==f)continue;
		dfs(v,u);
	}
}
struct Seg_Tree
{
	int lca;
}t[maxn<<2];
void build(int rt,int l,int r)
{
	if(l==r)
	{
		t[rt].lca=l;
		return ;
	}
	int mid=l+r>>1;
	build(rt<<1,l,mid);
	build(rt<<1|1,mid+1,r);
	t[rt].lca=get_lca(t[rt<<1].lca,t[rt<<1|1].lca);
}
int query(int rt,int l,int r,int x,int y)
{
	if(l>y || r<x)return 0;
	if(l>=x && r<=y)return t[rt].lca;
	int mid=l+r>>1;
	int p=query(rt<<1,l,mid,x,y),p1=query(rt<<1|1,mid+1,r,x,y);
	if(!p || !p1)return p^p1;
	return get_lca(p,p1);
}
struct deskman_Tree
{
	int lc,rc,max,max1,max2;
}t1[maxn<<5];
int cnt11;
void change(int rt,int &rt1,int l,int r,int x,int y,int y1)
{
	if(rt1==0)rt1=++cnt11;
	if(l==r)
	{
		t1[rt1].max=y;
		t1[rt1].max1=y1;
		return ;
	}
	int mid=l+r>>1;
	if(x>mid)
	{
		t1[rt1].lc=t1[rt].lc;
		change(t1[rt].rc,t1[rt1].rc,mid+1,r,x,y,y1);
	}
	else
	{
		t1[rt1].rc=t1[rt].rc;
		change(t1[rt].lc,t1[rt1].lc,l,mid,x,y,y1);
	}
	t1[rt1].max=max(t1[t1[rt1].lc].max,t1[t1[rt1].rc].max);
	t1[rt1].max1=max(t1[t1[rt1].lc].max1,t1[t1[rt1].rc].max1);
}
int ask(int rt,int l,int r,int x)
{
	int mid=l+r>>1;
	if(l==r)
	{
		return l;
	}
	if(t1[t1[rt].rc].max>=x)return ask(t1[rt].rc,mid+1,r,x);
	return ask(t1[rt].lc,l,mid,x);
}
stack<int>s;
struct St
{
	int L,R,id;
}myz[maxn];
int rt[maxn];
int zsw[maxn];
bool cmp(St x,St y)
{
	return x.L<y.L;
}
struct Seg_Tree1
{
	vector<pair<int ,int> >p;
}t2[maxn<<2];
inline void build1(int rt,int l,int r)
{
	if(l==r)
	{
		t2[rt].p.push_back({myz[l].R-myz[l].L+1,dep[myz[l].id]});
		
		return ;
	}
	int mid=l+r>>1;
	build1(rt<<1,l,mid);
	build1(rt<<1|1,mid+1,r);
	int p1=0;
	int p2=0;
	while(p1<t2[rt<<1].p.size() && p2<t2[rt<<1|1].p.size())
	{
		pair<int,int> q1=t2[rt<<1].p[p1],q2=t2[rt<<1|1].p[p2];
		if(q1.first<q2.first)t2[rt].p.push_back(q1),p1++;
		else t2[rt].p.push_back(q2),p2++;
	}
	while(p1<t2[rt<<1].p.size())
	{
		pair<int,int> q1=t2[rt<<1].p[p1];
		t2[rt].p.push_back(q1);
		p1++;
	}
	while(p2<t2[rt<<1|1].p.size())
	{
		pair<int,int> q1=t2[rt<<1|1].p[p2];
		t2[rt].p.push_back(q1);
		p2++;
	}
	for(int i=t2[rt].p.size()-2;i>=0;i--)
	{
		t2[rt].p[i].second=max(t2[rt].p[i].second,t2[rt].p[i+1].second);
	}
}
int ask1(int rt,int l,int r,int x,int y,int k)
{
	if(l>y || r<x)return 0;
	if(l>=x && r<=y)
	{
		if(t2[rt].p[t2[rt].p.size()-1].first<k)return 0;
		int L=0,R=t2[rt].p.size()-1;
		while(L<=R)
		{
			int mid=L+R>>1;
			if(t2[rt].p[mid].first>=k)R=mid-1;
			else L=mid+1;
		}
		if(L<0)L=0;
		return t2[rt].p[L].second;
	}
	int mid=l+r>>1;
	return max(ask1(rt<<1,l,mid,x,y,k),ask1(rt<<1|1,mid+1,r,x,y,k));
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	lg[1]=0;
	for(int i=2;i<=n;i++)
	{
		lg[i]=lg[i>>1]+1;
	}
	int maxx=0;
	dfs(1,1);
	st();
	for(int i=1;i<=n;i++)maxx=max(maxx,dep[i]);
	if(maxx!=n)
	{
		scanf("%d",&q);
		build(1,1,n);
		for(int i=1;i<=q;i++)
		{
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			int maxx=0;
			for(int j=l;j+k-1<=r;j++)
			{
				maxx=max(maxx,dep[query(1,1,n,j,j+k-1)]);
			}
			printf("%d\n",maxx);
		}
	}	
	else
	{
		s.push(0);
		for(int i=1;i<=n;i++)
		{
			while(!s.empty() && dep[s.top()]>dep[i])s.pop();
			myz[i].L=s.top()+1;
			s.push(i);
		}
		while(!s.empty())s.pop();
		s.push(n+1);
		for(int i=n;i>=1;i--)
		{
			while(!s.empty() && dep[s.top()]>dep[i])s.pop();
			myz[i].R=s.top()-1;
			myz[i].id=i;
			s.push(i);
		}
		sort(myz+1,myz+n+1,cmp);
		build1(1,1,n);
		for(int i=1;i<=n;i++)
		{
			change(rt[i-1],rt[i],1,n,dep[myz[i].id],myz[i].R,myz[i].R-myz[i].L+1);
			zsw[myz[i].L]=i;
		}
		for(int i=1;i<=n;i++)if(zsw[i]==0)zsw[i]=zsw[i-1];
		scanf("%d",&q);
		for(int i=1;i<=q;i++)
		{
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			int p1=ask(zsw[l-1],1,n,l+k-1);cout<<p1<<" ";
			p1=max(p1,ask1(1,1,n,zsw[l-1]+1,zsw[r-k+1],r));
			
			printf("%d\n",p1);
		}
	}
	return 0;
}
