#include<bits/stdc++.h>

using namespace std;

const int maxn =5e5+10;
int dfn[maxn], siz[maxn],hson[maxn], depth[maxn], tops[maxn], fa[maxn];
//int sgt[maxn*4];
int n;
vector<int> g[maxn];

int cnt;
void dfs1(int u, int dep, int p){
	if(u>n) return;
//	dfn[u] = ++cnt;
	depth[u] = dep;
	siz[u] = 1;
	fa[u] = p;
	
	for(int v: g[u]){
		if(v == p) continue;
		dfs1(v, dep+1, u);
		if(siz[v] > hson[u]) hson[u] = v;
		siz[u] += siz[v];
	}	
}
int chain;
void dfs2(int u, int top, int p){
	if(u > n) return;
//	if(dfn[u]!=0) cout<<"sth went wrong\n";
	dfn[u] == ++cnt;
	tops[u] = top;
	
	if(hson[u])	dfs2(hson[u], top, u);
	
	for(int v: g[u]){
		if(v==p) continue;
		if(v == hson[u]) continue;
		else dfs2(v, v, u);
	}
}

int lca(int x, int y){
//	if(depth[x] < depth[y]) swap(x, y);
	
	while(tops[x] != tops[y]){
		if(depth[ tops[x] ] > depth[ tops[y] ]) x = fa[tops[x] ];
		else y = fa[tops[y]];
	}
	if(depth[x] < depth[y]) return x;
	else return y;
	
}

int powerquery(int l, int r, int k)
{
	int cur_dep=0;
	int deepest=0;
	
//	for(int len=k;len<=r-l-1;len++){
//		for(int s=l;s+len<=r;s++){
//			int lc=0;
//			lc = lca(s, s+len-1);
//			for(int i=1;i<=len;i++){
//				lc = lca(lc, i+s-1);
//			}
//			if(depth[lc] > cur_dep){
//				deepest = lc;
//				cur_dep = depth[lc];
//			}
//		}
//	}
	for(;l+k<=r+1;l++){
		int lc = 0;
		lc = lca(l, l+k-1);
		for(int i=1;i<=k;i++){
			lc = lca(lc, i+l-1);
		}
		if(depth[lc] > cur_dep){
				deepest = lc;
				cur_dep = depth[lc];
			}
	}
//	for(int s=l;s+k+1<=r;s++){
//		int lc=0;
//		lc = lca(s, s+k-1);
//		for(int i=1;i<=k;i++){
//			lc = lca(lc, i+s-1);
//			if(depth[lc] > cur_dep){
//				deepest = lc;
//				cur_dep = depth[lc];
//			}
//		}
//	}
//	if(cur_dep == 0) cout<<"0: "<<l<<" "<<r<<" "<<k<<endl;
	return cur_dep;
}
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1,1,0);
//	cout<<"fu\n";
	dfs2(1,1,0);
//	cout<<"sion\n";
	
	int q;
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		cout<<powerquery(l,r,k)<<endl;	
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++){
//			cout<<i<<" "<<j<<" lca is:"<<lca(j, i)<<endl;
//		}
//	}
}
