#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
template<class T> int cmn(T &x,T y){return y<x?x=y,1:0;}
template<class T> int cmx(T &x,T y){return y>x?x=y,1:0;}

const int N=5e5+3;
int n,m,f[20][N],g[20][N];
vi adj[N];
array<int,3> q[N];

int dfn[N],tim,st[20][N],dep[N];
void dfs(int u,int par){
	dfn[u]=++tim;
	st[0][dfn[u]]=par;
	dep[u]=dep[par]+1;
	for(int v:adj[u]) if(v!=par) dfs(v,u);
}
int mg(int x,int y){
	return dfn[x]<dfn[y]?x:y;
}
int mgg(int x,int y){
	return dfn[x]>dfn[y]?x:y;
}
int lca(int x,int y){
	if(x==y) return x;
	x=dfn[x];
	y=dfn[y];
	if(x>y) swap(x,y);
	x++;
	int k=__lg(y-x+1);
	return mg(st[k][x],st[k][y-(1<<k)+1]);
}

int fqry(int l,int r){
	int k=__lg(r-l+1);
	return mg(f[k][l],f[k][r-(1<<k)+1]);
}

int gqry(int l,int r){
	int k=__lg(r-l+1);
	return mgg(g[k][l],g[k][r-(1<<k)+1]);
}

namespace A{
	int chk(){
		int c1=0,c2=0;
		F(i,1,n){
			if(si(adj[i])>2) return 0;
			if(si(adj[i])==1) c1++;
			if(si(adj[i])==2) c2++;
		}
		return c1==2&&c2==n-2;
	}
	void main(){
		cerr<<"A\n";
		F(i,1,m){
			int r=q[i][1],k=q[i][2];
			cout<<r-k+1<<'\n';
		}
	}
}

namespace bf{
	void main(){
		cerr<<"bf\n";
		F(i,1,m){
			int l=q[i][0],r=q[i][1],k=q[i][2];
			int ans=0;
			F(i,l,r-k+1){
				int p=fqry(i,i+k-1),q=gqry(i,i+k-1);
				cmx(ans,dep[lca(p,q)]);
			}
			cout<<ans<<'\n';
		}
	}
}

void run(){
	cin>>n;
	F(i,1,n-1){
		int u,v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1,0);
	F(i,1,n) f[0][i]=g[0][i]=i;
	F(i,1,18) F(j,1,n-(1<<i)+1){
		st[i][j]=mg(st[i-1][j],st[i-1][j+(1<<(i-1))]);
		f[i][j]=mg(f[i-1][j],f[i-1][j+(1<<(i-1))]);
		g[i][j]=mgg(g[i-1][j],g[i-1][j+(1<<(i-1))]);
	}
	cin>>m;
	F(i,1,m) cin>>q[i][0]>>q[i][1]>>q[i][2];
	if(A::chk()){
		A::main();
		return; 
	}
	bf::main();
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin.tie(0)->ios::sync_with_stdio(0);
	int t=1;
//	cin>>t;
	while(t--) run();
}
