#include<bits/stdc++.h>
#define ll long long
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define fd(i,r,l) for(int i=r;i>=l;i--)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define N 500005
using namespace std;
bool Mbe;
void read(int&x){
	int b=1;
	char c=getchar();
	while(c<'0'||c>'9')b=(c=='-'?-1:b),c=getchar();
	x=0;
	while(c>='0'&&c<='9')x=x*10+(c^48),c=getchar();
	x*=b;
}
void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int n,q,x,y,l[N],r[N],k[N];
vector<int>v[N];
int fa[21][N],dep[N];
void dfs(int x,int f){
	dep[x]=dep[f]+1,fa[0][x]=f;
	fo(i,1,20)fa[i][x]=fa[i-1][fa[i-1][x]];
	for(int i:v[x])if(i^f)dfs(i,x);
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	fo(i,0,20)if(((dep[x]-dep[y])>>i)&1)x=fa[i][x];
	if(x==y)return x;
	fd(i,20,0)if(fa[i][x]^fa[i][y])x=fa[i][x],y=fa[i][y];
	return fa[0][x];
}
int stl[21][N];
void init(){
	fo(i,1,n)stl[0][i]=i;
	fo(j,1,20)fo(i,1,n-(1<<j)+1)stl[j][i]=lca(stl[j-1][i],stl[j-1][i+(1<<(j-1))]);
}
int qrl(int l,int r){
	if(l>r)return 0;
	int k=log2(r-l+1);
	return lca(stl[k][l],stl[k][r-(1<<k)+1]);
}
bool Mde;
signed main(){
	freopen("query.in","r",stdin),freopen("query.out","w",stdout);
	read(n);
	fo(i,1,n-1)read(x),read(y),v[x].pb(y),v[y].pb(x);
	dfs(1,0),init(),read(q);
	fo(i,1,q)read(l[i]),read(r[i]),read(k[i]);
	fo(i,1,q){
		int maxn=0;
		fo(j,l[i],r[i]-k[i]+1)maxn=max(maxn,dep[qrl(j,j+k[i]-1)]);
		write(maxn),puts("");
	}
	cerr<<abs((&Mbe)-(&Mde))/1024./1024.<<" MB\n";
	return 0;
}
