#include<bits/stdc++.h>
#define mems(x,y) memset(x,y,sizeof x)
#define eb emplace_back
#define Mp make_pair
#define il inline
#define gc getchar
#define pc putchar
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define drep(i,x,y) for(int i=(x);i>=(y);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>
il void read(T &x){
	int f=1;x=0;
	char c=gc();
	while(c<'0'||c>'9'){
		if(c=='-'){
			f=-1;
		}
		c=gc();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=gc();
	}
	x*=f;
}
template<typename T,typename ...Args>
void read(T &x,Args &...args){
	read(x),read(args...);
}
const int N=5e5+7,M=5e3+7,inf=0x3f3f3f3f,mod=0;
const ll INF=1ll*inf*inf;
int n,m,fa[N],dep[N];
int f[M][M];
int tot,head[N];
struct node{
	int to,nxt;
}e[N<<1];
il void add(int u,int v){
	e[++tot]={v,head[u]},head[u]=tot;
}
void dfs(int u,int f){
	fa[u]=f,dep[u]=dep[f]+1;
	go(i,u){
		int v=e[i].to;
		if(v==f){
			continue;
		}
		dfs(v,u);
	}
}
il int getLca(int u,int v){
	if(dep[u]<dep[v]){
		swap(u,v);
	}
	while(dep[u]>dep[v]){
		u=fa[u];
	}
	while(u!=v){
		u=fa[u],v=fa[v];
	}
	return u;
}
void Yorushika(){
	read(n);
	rep(i,1,n-1){
		int u,v;read(u,v);
		add(u,v),add(v,u);
	}
	if(n<=5000){
		dfs(1,0);
		rep(i,1,n){
			f[i][i]=i;
		}
		rep(l,2,n){
			rep(i,1,n-l+1){
				int j=i+l-1;
				f[i][j]=getLca(f[i+1][j],f[i][j-1]);
			}
		}
		read(m);
		while(m--){
			int l,r,k;read(l,r,k);
			int ans=1;
			rep(i,l,r-k+1){
				ans=max(ans,dep[f[i][i+k-1]]);
			}
			printf("%d\n",ans);
		}
		return;
	}else{
		read(m);
		while(m--){
			puts("1");
		}
	}
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int t=1;
	// read(t);
	while(t--){
		Yorushika();
	}
}