#include<bits/stdc++.h>
#define LL long long
#define Maxn 500005
using namespace std;
int n,t;
vector<int> e[Maxn];
bool flgA;

int my2[Maxn<<1],mx[21][Maxn],mn[21][Maxn],st[21][Maxn<<1],cnt;
int d[Maxn],fa[Maxn],dfn[Maxn],raw[Maxn<<1],tot,dep[Maxn],dfnr[Maxn];
void dfs1(int x){
	dep[x] = dep[fa[x]] + 1;
	dfnr[x] = dfn[x] = ++tot;
	st[0][tot] = dep[x];
	raw[tot] = x;
	for(int y : e[x])if(y != fa[x]){
		fa[y] = x;
		dfs1(y);
		dfnr[x] = ++tot;
		st[0][tot] = dep[x];
	}
}

void pre1(){
	for(int i=2; i<=tot; i++) my2[i] = my2[i>>1] + 1;
	for(int i=1; i<=n; i++){
		mn[0][i] = dfn[i];
		mx[0][i] = dfnr[i];
	}
	for(int i=1; i<=20; i++){
		for(int j=1; j+(1<<i)-1<=n; j++){
			mx[i][j] = max(mx[i-1][j], mx[i-1][j+(1<<(i-1))]);
			mn[i][j] = min(mn[i-1][j], mn[i-1][j+(1<<(i-1))]);
		}
	}
	for(int i=1; i<=20; i++){
		for(int j=1; j+(1<<i)-1<=tot; j++){
			st[i][j] = min(st[i-1][j], st[i-1][j+(1<<(i-1))]);
		}
	}
}
int mxqry(int l, int r){
	int x = my2[r-l+1]; return max(mx[x][l], mx[x][r-(1<<x)+1]);
}
int mnqry(int l, int r){
	int x = my2[r-l+1]; return min(mn[x][l], mn[x][r-(1<<x)+1]);
}
int stqry(int l, int r){
	int x = my2[r-l+1]; return min(st[x][l], st[x][r-(1<<x)+1]);
}

int calc(int l, int r){
	return stqry(mnqry(l,r), mxqry(l,r));
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,x,y; i<n; i++){
		scanf("%d%d",&x,&y);
		e[x].emplace_back(y); d[x]++;
		e[y].emplace_back(x); d[y]++;
	}
	for(int i=1; i<=n; i++)if(d[i] > 2){
		flgA = 0; break;
	}
//	if(d[1]==1 && flgA){ slvA(); return 0; }
	
	dfs1(1);
	pre1();
	
	scanf("%d",&t);
	int x,y,z,ans;
	while(t--){
		scanf("%d%d%d",&x,&y,&z);
		ans = 0;
		for(int l=x,r=x+z-1; r<=y; l++,r++){
			ans = max(ans, calc(l,r));
		}
		printf("%d\n",ans);
	}
	return 0;
}

