#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int em,e[10000],nxt[10000],lst[10000];
int father[1000][53],lg[100000],dep[100000];
int father1[100000];
int n,x,y,q,l,r,k;
void insert(int x,int y){em++,e[em]=y,nxt[em]=lst[x],lst[x]=em;}
void dfs(int x,int fa){
	dep[x]=dep[fa]+1;father[x][0]=fa;
	father1[x]=fa;
	for(int i=1;i<=lg[dep[x]];i++) father[x][i]=father[father[x][i-1]][i-1];
	for(int i=lst[x];i;i=nxt[i]){
		if(e[i]==fa) continue;
		dfs(e[i],x);
	}
}
int lc_a(int x,int y){
	if(dep[x]<dep[y]) swap(x,y);
	while(dep[x]>dep[y]){
		x=father[x][lg[dep[x]-dep[y]]-1];
		if(dep[x]<dep[y]) swap(x,y);
	}
	if(x==y) return x;
	for(int i=lg[dep[x]]-1;i>=0;i--){
		if(father[x][i]!=father[y][i]) x=father[x][i],y=father[y][i];
	}
	return father[x][0];
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++) scanf("%d%d",&x,&y),insert(x,y),insert(y,x);
	for(int i=1;i<=n;i++) lg[i]=lg[i-1]+(1<<lg[i-1]==i);
	dfs(1,0);
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		for(int len=k;len+l-1<=r;len++){
			for(int start=l;start+len-1<=r;start++){
				int maxx1=lc_a(start,start+1);
				for(int now=start+2;now<=start+len-1;now++) maxx1=lc_a(maxx1,now);
				ans=max(ans,dep[maxx1]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
