#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
typedef long long ll;
namespace abcdefg {
	constexpr int N=5e5+7;
	#define isdigit(x) (x>='0'&&x<='9')
	#define gc getchar_unlocked
	#define pc putchar_unlocked
	template <typename T>
	void read(T &x) {
		x=0;
		char ch=gc();
		for(;!isdigit(ch);ch=gc());
		for(;isdigit(ch);ch=gc()) x=(x<<3)+(x<<1)+(ch^48);
	}
	template <typename T>
	void write(T x,char ch) {
		static int st[40];
		int top=0;
		do {
			st[top++]=x%10;
			x/=10;
		}while(x);
		while(top) pc(st[--top]^48); 
		pc(ch);
	}
	int n,u,v,q,l,r,k;
	vector<int> to[N];
	int dep[N],dfn[N],idfn[N],dfn0,st[30][N];
	int mndfn[30][N],mxdfn[30][N];
	int ans;
	void dfs(int u,int f) {
		dfn[u]=++dfn0;
		idfn[dfn0]=u;
		dep[u]=dep[f]+1;
		st[0][dfn0]=dep[f];
		mndfn[0][u]=dfn0;
		mxdfn[0][u]=dfn0;
		for(int v : to[u]) {
			if(v^f) {
				dfs(v,u);
			}
		}
	}
	void lcainit() {
		int lg=__lg(n);
		rep(k,1,lg) for(int i=1;i+(1<<k)-1<=n;i++) st[k][i]=min(st[k-1][i],st[k-1][i+(1<<(k-1))]);
	}
	int getlca(int mn,int mx) {
		if(mn==mx) return dep[idfn[mn]];
		++mn;
		int lg=__lg(mx-mn+1);
		return min(st[lg][mn],st[lg][mx-(1<<lg)+1]);
	}
	void dfninit() {
		int lg=__lg(n);
		rep(k,1,lg) for(int i=1;i+(1<<k)-1<=n;i++) mndfn[k][i]=min(mndfn[k-1][i],mndfn[k-1][i+(1<<(k-1))]), mxdfn[k][i]=max(mxdfn[k-1][i],mxdfn[k-1][i+(1<<(k-1))]);
	}
	int getmin(int l,int r) {
		int lg=__lg(r-l+1);
		return min(mndfn[lg][l],mndfn[lg][r-(1<<lg)+1]);
	}
	int getmax(int l,int r) {
		int lg=__lg(r-l+1);
		return max(mxdfn[lg][l],mxdfn[lg][r-(1<<lg)+1]);
	}
	void main() {
		read(n);
		rep(i,1,n-1) {
			read(u),read(v);
			to[u].push_back(v), to[v].push_back(u);
		}
		dfs(1,0);
		lcainit();
		dfninit();
		read(q);
		// rep(i,0,2) {
		// 	rep(j,1,n) pf("%d ",mxdfn[i][j]); pf("\n");
		// }
		rep(i,1,q) {
			read(l),read(r),read(k);
			ans=0;
			rep(j,l,r-k+1) ans=max(ans,getlca(getmin(j,j+k-1),getmax(j,j+k-1)));
			write(ans,'\n');
		}
	}
}
int main() {
	#ifdef LOCAL
	freopen("my.out","w",stdout);
	#else 
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	#endif
	abcdefg :: main();
}