#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 1e6 + 5;
int qwq,n,u,v,q,l,r,k,dep[N],dfn[N],fst[N],cnt,rev[N],lca[N][25],CNT,root[N];
vector<int> g[N],v2;
int len,st[N][25],LOG[N];
void build(){
	LOG[0] = -1;
	for(int i = 1;i <= len;i++)LOG[i] = LOG[i >> 1] + 1;
	for(int j = 1;j <= LOG[len];j++){
		for(int i = 1;i + (1 << j) - 1 <= len;i++){
			st[i][j] = min(st[i][j - 1],st[i + (1 << j - 1)][j - 1]);
		}
	}
}
int query(int l,int r){
	int k = LOG[r - l + 1];
	return min(st[l][k],st[r - (1 << k) + 1][k]);
}
int LCA(int x,int y){
	int t1 = min(fst[x],fst[y]),t2 = max(fst[x],fst[y]);
	return rev[query(t1,t2)];
}
int lca2(int l,int r){// lca [l,r]
	int k = LOG[r - l + 1];
	return LCA(lca[l][k],lca[r - (1 << k) + 1][k]);
}
void dfs(int u,int fa){
	dep[u] = dep[fa] + 1;
	dfn[u] = ++cnt;
	rev[cnt] = u;
//	cout << u << " " << cnt << endl;
	st[++len][0] = dfn[u];
	fst[u] = len;
	for(auto v : g[u]){
		if(v == fa)continue;
		dfs(v,u);
		st[++len][0] = dfn[u];
	}
}
int bf(int l,int r,int k){
	int ans = 0;
	for(int i = l;i + k - 1 <= r;i++)ans = max(ans,dep[lca2(i,i + k - 1)]);
	return ans;
}
struct node{
	int ls,rs,L,R,ans,lmax,rmax;
	int size(){return R - L + 1;}
	bool all(){return lmax == R - L + 1;}
}tree[N << 5];
node operator+(node a,node b){
	node c;
	c.ans = max(max(a.ans,b.ans),a.rmax + b.lmax);
	c.lmax = (a.all() ? a.size() + b.lmax : a.lmax);
	c.rmax = (b.all() ? b.size() + a.rmax : b.rmax);
	c.L = a.L,c.R = a.R;
	return c;
}
void pushup(int p){
	int ls = tree[p].ls,rs = tree[p].rs;
	tree[p].ans = max(max(tree[ls].ans,tree[rs].ans),tree[ls].rmax + tree[rs].lmax);
	tree[p].lmax = (tree[ls].all() ? tree[ls].size() + tree[rs].lmax : tree[ls].lmax);
	tree[p].rmax = (tree[rs].all() ? tree[rs].size() + tree[ls].rmax : tree[rs].rmax);
}
void update(int lst,int &p,int L,int R,int x){
	if(!p)p = ++CNT;
	tree[p].L = L,tree[p].R = R;
	if(L == R){
		tree[p].ans = tree[p].lmax = tree[p].rmax = 1;
		return;
	}
	int mid = (L + R) / 2;
	if(x <= mid)tree[p].rs = tree[lst].rs,update(tree[lst].ls,tree[p].ls,L,mid,x);
	else tree[p].ls = tree[lst].ls,update(tree[lst].rs,tree[p].rs,mid + 1,R,x);
	pushup(p);
}
node query(int p,int L,int R,int l,int r){
//	cout << p << " " << L << " " << R << " " << l << " " << r << endl;
	if(!p)return {0,0,L,R,0,0};
	if(l <= L && R <= r)return tree[p];
	int mid = (L + R) / 2;
	if(l <= mid && mid < r)return query(tree[p].ls,L,mid,l,r) + query(tree[p].rs,mid + 1,R,l,r);
	else if(l <= mid)return query(tree[p].ls,L,mid,l,r);
	else return query(tree[p].rs,mid + 1,R,l,r);
}
int QwQ(int l,int r,int k){
	int L = 1,R = n,ans = 1;
	while(L <= R){
		int mid = (L + R) / 2;
		if(query(root[mid],l,r,1,n).ans >= k)ans = mid,L = mid + 1;
		else R = mid - 1;
	}
	return ans;
}
int 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;i < n;i++)cin >> u >> v,g[u].push_back(v),g[v].push_back(u);
	dfs(1,0);
	build();
	LOG[0] = -1;
	for(int i = 1;i <= n;i++)LOG[i] = LOG[i >> 1] + 1,lca[i][0] = i;
	for(int j = 1;j <= LOG[n];j++){
		for(int i = 1;i + (1 << j) - 1 <= n;i++){
			lca[i][j] = LCA(lca[i][j - 1],lca[i + (1 << j - 1)][j - 1]);
		}
	}
	for(int i = 1;i <= n;i++)v2.push_back(i);
	sort(v2.begin(),v2.end(),[](int a,int b){return dep[a] < dep[b];});
	for(int i = n;i >= 1;i--){
		update(root[i + 1],root[i],1,n,v2[i - 1]);
//		cout << v2[i - 1] << endl;
//		for(int j = 1;j <= n;j++)cout << query(root[i],1,n,j,j).ans << " ";cout << endl;
	}
//	for(int i = 1;i <= len;i++)cout << st[i][0] << " ";cout << endl;
	cin >> q;
	while(q--){
		cin >> l >> r >> k;
		if(k == 1 || (n <= 5000 && q <= 5000) || k == r - l + 1)cout << bf(l,r,k) << endl;
		else cout << QwQ(l,r,k) << endl;
	}
}
