#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
using namespace std;

const int N = 5e5+10, M = 1e6+10, mod = 1e9+7;
#define ll long long

int n, q;
int cnt, head[N], to[M], nxt[M];
int LCA[5005][5005];
int fa[N], son[N], top[N], siz[N], dep[N];

void add(int u, int v) {
	to[++cnt] = v;
	nxt[cnt] = head[u];
	head[u] = cnt;
}

void dfs1(int x, int f) {
	fa[x] = f; siz[x] = 1; dep[x] = dep[f]+1;
	for(int i = head[x]; i; i = nxt[i]) {
		int y = to[i]; if(y == f) continue;
		dfs1(y,x);
		siz[x] += siz[y];
		if(siz[son[x]] < siz[y]) son[x] = y; 
	}
}

void dfs2(int x, int topf) {
	top[x] = topf;
	if(!son[x]) return;
	dfs2(son[x],topf);
	for(int i = head[x]; i; i = nxt[i]) {
		int y = to[i]; if(y == son[x] || y == fa[x]) continue;
		dfs2(y,y);
	}
}

int lca(int x, int y) {
	while(top[x] != top[y]) {
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		x = fa[top[x]];
	}
	if(dep[x] > dep[y]) return y;
	return x;
}

int main() {
	freopen("query.in","r",stdin); 
	freopen("query.out","w",stdout);

	scanf("%d",&n);
	for(int i = 1, u, v; i < n; i++) {
		scanf("%d%d",&u,&v); add(v,u); add(u,v);
	}
	
	scanf("%d",&q);
	
	dfs1(1,0);
	dfs2(1,1);
	
	for(int i = 1; i <= n; i++) LCA[i][i] = i;
	for(int l = 2; l <= n; l++) {
		for(int i = 1; i <= n; i++) {
			int j = i+l-1; if(j > n) continue;
			int mid = (i+j)>>1;
			LCA[i][j] = lca(LCA[i][mid], LCA[mid+1][j]);
		}
	}
	
	while(q--) {
		int l, r, k;
		scanf("%d%d%d",&l,&r,&k);
		int maxn = -1e9;
		for(int len = k; len <= r-l+1; len++) {
			for(int i = l; i <= r; i++) {
				int j = i+len-1; if(j > r) continue;
				maxn = max(maxn,dep[LCA[i][j]]);
			}
		}
		printf("%d\n",maxn);
	}

	return 0;
}
