#include<bits/stdc++.h>
#define son e[i].to

using namespace std;
const int MAXN = 1e5+5;
template<typename ...Args>
inline void logs(char *str,Args ...args){
	fprintf(stderr,str,args...);
}
struct edge{
	int to,nxt;
}e[MAXN];
int head[MAXN],tot = 0;
int n,q;
int fa[MAXN][25],dep[MAXN];
bool iss = true;

inline void addedge(int a,int b){e[++tot] = (edge){b,head[a]},head[a] = tot;}

void dfs(int r,int F){
	dep[r] = dep[F]+1;
	fa[r][0] = F;
	for(int i = 1;i<=20;i++){
		fa[r][i] = fa[fa[r][i-1]][i-1];
	}
	int tt = 0;
	for(int i = head[r];i;i = e[i].nxt){
		if(son != F)
			dfs(son,r),tt++;
	}
	if(tt > 1)
		iss = false;
}

int lca(int a,int b){
	if(dep[a]<dep[b])
		swap(a,b);
	for(int i = 20;~i;i--)
		if(dep[fa[a][i]] >= dep[b])
			a = fa[a][i];
	if(a == b)
		return a;
//	logs("A:%d B:%d \n",a,b);
	for(int i = 20;~i;i--)
		if(fa[a][i] != fa[b][i])
			a = fa[a][i],b = fa[b][i];
//	logs("A:%d B:%d \n",a,b);
	while(a != b)
		a = fa[a][0],b = fa[b][0];
//	logs("A:%d B:%d \n",a,b);
	return a;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i = 1,a,b;i<n;i++)
		cin>>a>>b,addedge(a,b),addedge(b,a);
	dfs(1,1);
	
	cin>>q;
	if(iss){
		while(q--){
			int l,r,k;
			cin>>l>>r>>k;
			int ans = 0;
			for(int L = l,R = l+k-1;R<=r;L++,R++){
				ans = max(ans,min(dep[L],dep[R]));
			}
			cout<<ans<<'\n';
		}
	} else {
		while(q--){
			int l,r,k;
			cin>>l>>r>>k;
			int ans = 0;
			for(int L = l,R = l+k-1;R<=r;L++,R++){
				ans = max(ans,dep[lca(L,R)]);
			}
			cout<<ans<<'\n';
		}
	}
}

