#include <bits/stdc++.h>

#define FRR(file) freopen(file,"r",stdin)
#define FRW(file) freopen(file,"w",stdout)
#define _rep(i,a,b) for (int i=(a);i<=(b);++i)
#define _rrep(i,a,b) for (int i=(a);i>=(b);--i)
#define _reps(i,a,b,c) for (int i=(a);i<=(b);c)
#define _rreps(i,a,b,c) for (int i=(a);i>=(b);c)
#define _graph(i,u) for (int i=h[u];~i;i=ne[i])
#define _iter(it,a) for (auto it=a.begin();it!=a.end();++it)
#define LL long long

using namespace std;

const int N=500005;
const int M=1000005;
const int K=30;

int n,Q;
int e[M],ne[M],h[N],tot;
int dep[N];
int f[N][K];
queue<int> q;

void add(int a,int b) {
	e[tot]=b,ne[tot]=h[a],h[a]=tot++;
}

void bfs() {
	q.push(1);
	dep[1]=1;
	while (!q.empty()) {
		int u=q.front(); q.pop();
		_graph(i,u) {
			if (!dep[e[i]]) {
				dep[e[i]]=dep[u]+1;
				f[e[i]][0]=u;
				_rep(i,1,K-1) f[e[i]][i]=f[f[e[i]][i-1]][i-1];
				q.push(e[i]);
			}
		}
	}
}

int lca(int a,int b) {
	if (dep[a]<dep[b]) swap(a,b);
	_rrep(i,K-1,0) if (dep[f[a][i]]>=dep[b]) a=f[a][i];
	if (a==b) return a;
	_rrep(i,K-1,0) if (f[a][i]!=f[b][i]) a=f[a][i],b=f[b][i];
	return f[a][0];
}

int main() {
	FRR("query.in");
	FRW("query.out");
	memset(h,-1,sizeof(h));
	scanf("%d",&n);
	_rep(i,1,n-1) {
		int a,b;
		scanf("%d %d",&a,&b);
		add(a,b); add(b,a);
	}
	bfs();
	scanf("%d",&Q);
	while (Q--) {
		int l,r,k;
		scanf("%d %d %d",&l,&r,&k);
		int ans=1;
		_rep(len,k,r-l+1) {
//		int len=k;
			_rep(i,l,r-len+1) {
				int j=i+len-1;
				int g=i;
				_rep(t,i+1,j) g=lca(g,t);
//				cout<<i<<" "<<j<<" "<<g<<" "<<dep[g]<<endl;
				ans=max(ans,dep[g]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
