#include <bits/stdc++.h>
#define fo(i,l,r) for(int i = (l);i <= (r);++i)
#define fu(i,l,r) for(int i = (r);i >= (l);--i)
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
using namespace std;
const int N = 5e5+5;
const int M = 1e6+5;
bool ST;
int st[N],to[M],nxt[M],cnt;
int n,m;
void read(int &x)
{
	x=0;char c=getchar();int fh=1;
	while(c > '9' or c < '0')
	{
		if(c == '-') fh = -1;
		c = getchar();
	}
	while(c >= '0' and c <= '9')
	{
		x = x * 10 + c - '0';
		c = getchar();
	}
	x *= fh;
	return ;
}
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=st[x];
	st[x]=cnt;
	return ;
}
int rd[N],maxrd;
int father[N],top[N],deep[N];
int sz[N],hson[N];
void dfs1(int x,int fa)
{
	father[x] = fa;
	deep[x] = deep[fa]+1;
	sz[x] = 1;
	for(int i = st[x];i;i=nxt[i])
	{
		int g = to[i];
		if(g == fa) continue;
		dfs1(g,x);
		sz[x] += sz[g];
		if(sz[hson[x]] < sz[g])
			hson[x] = g;
	}
	return ;
}
void dfs2(int x,int fop)
{
	top[x] = fop;
	if(hson[x]) dfs2(hson[x],fop);
	for(int i = st[x];i;i=nxt[i])
	{
		int g = to[i];
		if(g == father[x] or g == hson[x]) continue;
		dfs2(g,g);
	}
	return ;
}
int lca(int x,int y)
{
	if(!x or !y) return x+y;
	while(top[x] != top[y])
	{
		if(deep[top[x]] > deep[top[y]])
		{
			x = father[top[x]];
		}else{
			y = father[top[y]];
		}
	}
	if(deep[x] < deep[y]) return x;
	return y;
}
int tree[N*4];
void build(int l,int r,int index)
{
	if(l == r)
	{
		tree[index] = l;
		return ;
	}
	int mid = (l+r)>>1;
	build(l,mid,index<<1);
	build(mid+1,r,index<<1|1);
	tree[index] = lca(tree[index<<1],tree[index<<1|1]);
	return ;
}
int query(int l,int r,int index,int askl,int askr)
{
	if(l > askr or r < askl) return 0;
	if(askl <= l and r <= askr) return tree[index];
	int mid = (l+r)>>1;
	return lca(query(l,mid,index<<1,askl,askr),
		query(mid+1,r,index<<1|1,askl,askr));
}
struct asks{
	int x,y,k,id;
}q[N];
bool cmp(asks a,asks b)
{
	return a.k < b.k;
}
int ans[N],flca[N];
struct ZhuXiShu{
	int tree[N*100],cnt;
	int ls[N*100],rs[N*100];
	int roots[N];
	ZhuXiShu(){
		memset(roots,0,sizeof roots);
		cnt=0;
	}
	void build(int l,int r,int &x)
	{
		x = ++cnt;
		ls[x] = rs[x] = 0;
		tree[x] = 0;
		if(l == r)
		{
			return ;
		}
		int mid = (l+r)>>1;
		build(l,mid,ls[x]);
		build(mid+1,r,rs[x]);
		return ;
	}
	void insert(int pre,int l,int r,int &x,int askpos)
	{
		x = ++cnt;
		ls[x] = rs[x] = 0;
		if(l == r)
		{
			tree[x] = tree[pre]+1;
			return ;
		}
		int mid = (l+r)>>1;
		if(askpos <= mid) insert(ls[pre],l,mid,ls[x],askpos),rs[x]=rs[pre];
		else insert(rs[pre],mid+1,r,rs[x],askpos),ls[x]=ls[pre];
		tree[x] = tree[ls[x]]+tree[rs[x]];
	}
	int findkth(int pre,int now,int l,int r,int k)
	{
		if(l == r) return l;
		int mid = (l+r)>>1;
		int g = tree[ls[now]]-tree[ls[pre]];
		if(g >= k) return findkth(ls[pre],ls[now],l,mid,k);
		return findkth(rs[pre],rs[now],mid+1,r,k-g);
	}
}T;
void task_chain()
{
	T.build(1,n,T.roots[0]);
	fo(i,1,n) T.insert(T.roots[i-1],1,n,T.roots[i],deep[i]);
	fo(i,1,m)
	{
		int le = q[i].y-q[i].x+1;
		int kth = le-q[i].k+1;
		ans[q[i].id] = T.findkth(T.roots[q[i].x-1],T.roots[q[i].y],1,n,kth);
	}
	fo(i,1,m) printf("%d\n",ans[i]);
	return ;
}
bool EN;
int main()
{
//	cerr<<(&EN-&ST)/1024.0/1024.0;
	fre(query);
	read(n);
	fo(i,1,n-1)
	{
		int x,y;
		read(x),read(y);
		add(x,y),add(y,x);
		rd[x]++,rd[y]++;
		maxrd=max({maxrd,rd[x],rd[y]});
	}
	dfs1(1,0),dfs2(1,1);
	build(1,n,1);
	read(m);
	fo(i,1,m)
	{
		read(q[i].x),read(q[i].y);
		read(q[i].k),q[i].id = i;
		if(q[i].k == (q[i].y-q[i].x+1))
		{
			ans[i] = deep[query(1,n,1,q[i].x,q[i].y)];
		}
	}
	sort(q+1,q+1+m,cmp);
	if(maxrd <= 2)
	{
//		cerr<<"in";
		task_chain(); 
		return 0;
	}
	fo(i,1,n) flca[i] = i;
	int nowf = 1;
	fo(i,1,m)
	if(!ans[q[i].id])
	{
		while(nowf < q[i].k)
		{
			fo(j,1,n-nowf)
			if(flca[j] > 1)
				flca[j] = lca(flca[j],j+nowf);
			nowf++;
		}
		int L = 0;
		fo(j,q[i].x,q[i].y-q[i].k+1)
			L = max(L,deep[flca[j]]);
		ans[q[i].id] = L;
	}
	fo(i,1,m) printf("%d\n",ans[i]);
	return 0;
}
