#include <bits/stdc++.h>
#define N int(5e5+5)
using namespace std;

template<typename T>
inline void Read(T&k) {
	char c=getchar();
	while(!isdigit(c)) c=getchar();
	for(k=0; isdigit(c); c=getchar())
		k=k*10+c-'0';
} 

int fa[N][20], n, head[N], ecnt, dep[N], q, islink;
vector<int> G[N];

void getdep(int x, int f) {
	dep[x]=dep[f]+1;
	fa[x][0]=f;
	for(int i=1; i<20; i++) {
		fa[x][i] = fa[fa[x][i-1]][i-1];
	}
	for(int v:G[x]) {
		if(v==f) continue;
		getdep(v, x);
	}
	

}

int lca(int x, int y) {
	if(x==y) return x;
	
	if(dep[x]<dep[y]) swap(x, y);
	while(dep[x]>dep[y]) {
		for(int i=19; i>=0; i--) {
			if(!fa[x][i]) continue;
			if(dep[fa[x][i]]<dep[y]) continue;
			x=fa[x][i];
		}
	}
	if(x==y) return x;
	
	for(int i=19; i>=0; i--) {
		if(!fa[x][i]) continue;
		if(!fa[y][i]) continue;
		
		if(fa[x][i]==fa[y][i]) continue;
		x=fa[x][i];
		y=fa[y][i];
	}
	return fa[x][0];
}

bool checkLink() {
	int cnt=0;
	for(int i=1; i<=n; i++) {
		if(G[i].size()==1) cnt++;
	}
	return (cnt==2);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout); 
	Read(n);
	for(int i=1, u, v; i<n; i++) {
		Read(u), Read(v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	islink=checkLink();
	if(islink) {
		int f=0, p=1, cnt=0;
		while(true) {
			dep[p]=dep[f]+1;
			for(int v:G[p]) if(v!=f){
				f=p, p=v;
				continue;
			} 
			if(G[p].size()==1 && p!=1) break;
		}
		Read(q);
		while(q--) {
			int l, r, k, ans=0;
			Read(l), Read(r), Read(k);
			for(int i=l; i+k-1<=r; i++) {
				int LCA=i;
				for(int j=i+1; j<=i+k-1; j++)
				{
					if(dep[j]<dep[LCA]) LCA=j;
				}
				ans=max(ans, dep[LCA]);
			}
			cout<<ans<<'\n';
		}
		return 0;
	}
	
	getdep(1, 0);
	Read(q);
	while(q--) {
		int l, r, k, ans=0;
		Read(l), Read(r), Read(k);
		for(int i=l; i+k-1<=r; i++) {
			int LCA=i;
			for(int j=i+1; j<=i+k-1; j++)
				LCA=lca(LCA, j);
			ans=max(ans, dep[LCA]);
		}
		cout<<ans<<'\n';
	}
	
	return 0; 
} 
