#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define lowbit(x) (x & -x)

bool ST;
const int N = 5e5 + 10;
int n , T , q;
int h[N] , to[N << 1] , ne[N << 1] , idx;
int dep[N] , fa[N][21];
int st[N][21];
//int t[N << 5] , ls[N << 5] , rs[N << 5] , id[N] , cnt;

int read(){
	ll sum = 0;
	bool flag = true;
	char c = getchar();
	for(;!isdigit(c);c = getchar())if(c == '-')flag ^= true;
	for(;isdigit(c);c = getchar())sum = (sum << 1) + (sum << 3) + (c ^ 48);
	return flag ? sum : -sum;
}
void out_write(int x){if(x > 9)out_write(x / 10);putchar(x % 10 + '0');}
void write(int x){if(x < 0){putchar('-');out_write(-x);}else out_write(x);}
//NPIO is over.My OI life is over , too. What a pity!
//int build(int l , int r){
//	int root = ++ cnt;
//	if(l == r)return ;
//	int mid = (l + r) >> 1;
//	ls[root] = build(l , mid);
//	rs[root] = build(mid + 1 , r);
//	return root;
//}
//int updata(int l , int r , int rt , int x , int k){
//	int root = ++ cnt;
//	ls[root] = ls[rt];rs[root] = rs[rt];t[root] = t[rt] + k;
//	if(l == r && l == x)return root;
//	int mid = (l + r) >> 1;
//	if(x <= mid)ls[root] = updata(l , mid , ls[root] , x , k);
//	else rs[root] = updata(mid + 1 , r , rs[root] , x , k);
//	return root;
//}
//int query(int l , int r , int u , int v , int k){
//	if(l == r)return l;
//	int s = t[ls[v]] - t[ls[u]];
//	int mid = (l + r) >> 1;
//	if(s <= k)return query(l , mid , ls[u] , ls[v] , k);
//	else return query(mid + 1 , r , rs[u] , rs[v] , k - s);
//}
void add(int u , int v){to[++ idx] = v;ne[idx] = h[u];h[u] = idx;}
void dfs(int u , int f){
	dep[u] = dep[f] + 1;
	fa[u][0] = f;
	for(int i = 1;i <= 20;++ i){
		fa[u][i] = fa[fa[u][i - 1]][i - 1];
	}
	for(int i = h[u];~i;i = ne[i]){
		int v = to[i];
		if(v == f)continue;
		dfs(v , u);
	}
}
int lca(int x , int y){
	if(dep[x] < dep[y])swap(x , y);
	for(int i = 20;i >= 0;-- i){
		if(dep[fa[x][i]] >= dep[y]){
			x = fa[x][i];
		}
	}
	if(x == y)return x;
	for(int i = 20;i >= 0;-- i){
		if(fa[x][i] == 0)continue;
		if(fa[x][i] != fa[y][i]){
			x = fa[x][i];y = fa[y][i];
		}
	}
	return fa[x][0];
}
void init(){
	for(int i = 1;i <= n;++ i){
		st[i][0] = i;
	}
	for(int i = 1;(1 << i) <= n;++ i){
		for(int j = 1;j + (1 << i) - 1 <= n;++ j){
			st[j][i] = lca(st[j][i - 1] , st[j + (1 << (i - 1))][i - 1]);
//			cerr << j << " " << j + (1 << i) - 1 << " " << st[j][i] << endl;
		}
	}
}
int LCA(int l , int r){
	int s = log2(r - l + 1);
	return lca(st[l][s] , st[r - (1 << s) + 1][s]);
}
void work(){
	memset(h , -1 , sizeof h);
	n = read();
	for(int i = 1;i < n;++ i){
		int u , v;
		u = read();v = read();add(u , v);add(v , u);
	}
	dfs(1 , 0);
//	cerr << lca(3 , 4) << endl;
	q = read();
	if(n <= 5000){
		init();
		while(q --){
			int l , r , k;l = read();r = read();k = read();
			int ans = 0;
			for(int j = l;j + k - 1 <= r;++ j){
//				cerr << j << " " << j + k - 1 << " " << LCA(j , j + k - 1) << endl;
				ans = max(ans , dep[LCA(j , j + k - 1)]);
			}
			write(ans);putchar('\n');
		}
	}
	else {
//		if(check()){
//			
//			while(q --){
//				int l , r , k;l = read();r = read();k = read();
//				
//			}
//		}	
		init();
		while(q --){
			int l , r , k;l = read();r = read();k = read();
			int ans = dep[LCA(l , r)];
			write(ans);putchar('\n');
		}
	}
}
bool ED;

int main(){
	freopen("query.in" , "r" , stdin);
	freopen("query.out" , "w" , stdout);
//	cerr << ((&ST) - (&ED)) / 1024.0 / 1024.0 << endl;
//	double st = clock();
	T = 1;
	while(T --){work();}
//	double ed = clock();
//	cerr << (ed - st) / CLOCKS_PER_SEC << endl;
	return 0;
}

