#include<iostream>
#include<vector>
using namespace std;
int n;
vector<int> tr[500010];
int dep[500010];
int f[500010];
void dfs(int now,int fa) {
	dep[now]=dep[fa]+1;
	f[now]=fa;
	for(int i=0; i<tr[now].size(); i++) {
		if(tr[now][i]==fa)continue;
		dfs(tr[now][i],now);
	}
}
int lca(int x,int y) {
	while(dep[x]>dep[y])x=f[x];
	while(dep[y]>dep[x])y=f[y];
	while(x!=y)x=f[x],y=f[y];
	return x;
}
int main() {
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1; i<=n-1; i++) {
		int u,v;
		cin>>u>>v;
		tr[u].push_back(v);
		tr[v].push_back(u);
	}
	dfs(1,0);
	int q;
	cin>>q;
	while(q--) {
		int l,r,k;
		cin>>l>>r>>k;
		int maxn=0;
		for(int len=k; len<=(r-l+1); len++) {
			for(int i=l,j=l+len-1; j<=r; i++,j++) {
				int lcan=i;
				for(int k=i+1;k<=j;k++)lcan=lca(lcan,k);
				maxn=max(maxn,dep[lcan]);
			}
		}
		cout<<maxn<<endl;
	}
	return 0;
}
