#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5,INF = 1e9 + 7;

int n,q;
vector<int> e[N];
namespace substacka{
	const int LG = 20;
	int dfn[N],dfnn[N],dep[N],st[LG][N],sjc;
	int get(int u,int v){return (dfn[u] < dfn[v]) ? (u) : (v);}
	void dfs(int u,int fa){
		st[0][dfn[u] = ++sjc] = fa;dep[u] = dep[fa] + 1;
		dfnn[sjc] = u;
		for (int v : e[u]){
			if (v == fa) continue;
			dfs(v,u);
		}
	}int get_lca(int u,int v){
		if ((u = dfn[u]) > (v = dfn[v])) swap(u,v);
		if (u == v) return dfnn[u];
		int d = __lg(v - u++);
		return get(st[d][u],st[d][v - (1 << d) + 1]);
	}
	struct segmenttree{
		#define ls (u << 1)
		#define rs (u << 1 | 1)
		int maxn[N],minn[N];
		void push_up(int u){
			maxn[u] = max(maxn[ls],maxn[rs]);
			minn[u] = min(minn[ls],minn[rs]);
		}void build(int u,int l,int r){
			if (l == r) return minn[u] = maxn[u] = dfn[l],(void)0;
			int mid = l + r >> 1;build(ls,l,mid);build(rs,mid + 1,r);
			push_up(u);
		}pair<int,int> query(int u,int l,int r,int ql,int qr){
			if (ql <= l && r <= qr) return {minn[u],maxn[u]};
			int mid = l + r >> 1;
			if (ql > mid) return query(rs,mid + 1,r,ql,qr);
			if (qr <= mid) return query(ls,l,mid,ql,qr);
			pair<int,int> res = {INF,-INF};pair<int,int> lef = query(ls,l,mid,ql,qr),righ = query(rs,mid + 1,r,ql,qr);
			res.first = min(lef.first,righ.first);res.second = max(lef.second,righ.second);
			return res;
			
		}
	}seg1;
	void solve1(){
		dfs(1,0);
		for (int j = 1;j < LG;j++){
			for (int i = 1;i + (1 << j) - 1 <= n;i++){
				st[j][i] = get(st[j - 1][i],st[j - 1][i + (1 << j - 1)]);
			}
		}seg1.build(1,1,n);
		cin >> q;
		for (int i = 1,l,r,k;i <= q;i++){
			cin >> l >> r >> k;
			int maxx = -1;
			for (int j = l;j + k - 1 <= r;j++){
				int ll = j,rr = j + k - 1;
				pair<int,int> range = seg1.query(1,1,n,ll,rr);
				int mins = dfnn[range.first],maxs = dfnn[range.second];
				maxx = max(maxx,dep[get_lca(mins,maxs)]);
			}cout << maxx << "\n";
		}
	}
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> n;for (int i = 1,u,v;i < n;i++){
		cin >> u >> v;
		e[u].push_back(v);e[v].push_back(u);
	}substacka::solve1();
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
