#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define infile(filename) freopen(filename".in","r",stdin)
#define outfile(filename) freopen(filename".out","w",stdout)
#define usefile(filename) infile(filename),outfile(filename)
using namespace std; typedef long long ll; typedef unsigned long long ull;
char gc() { static const int BUF=1<<20; static char ch[BUF],*l=ch,*r=ch; return (l==r&&(r=(l=ch)+fread(ch,1,BUF,stdin),l==r))?EOF:*l++; }
template <typename T> void read(T &a) { static char ch,fushu; fushu=a=0; do ch=gc(); while(ch!='-'&&(ch<48||ch>57)); if(ch=='-') fushu=1,ch=gc(); do a=(a<<1)+(a<<3)+(ch^48),ch=gc(); while(ch>47&&ch<58); if(fushu) a=-a; return ; }
template <typename T,typename ...Args> void read(T &a,Args &...args) { read(a),read(args...); }
const int N=500099,LogN=21;
int n,q,em=0,e[N*2]={},ls[N]={},nx[N*2]={},fa[N]={},dfn[N]={},tdfn=0,deep[N]={},minn[N][LogN]={},st[N][LogN]={};
void insert(int x,int y) { e[++em]=y,nx[em]=ls[x],ls[x]=em; e[++em]=x,nx[em]=ls[y],ls[y]=em; }
void setup(int x) {
	int i,y; minn[dfn[x]=++tdfn][0]=x,st[x][0]=x;
	for(i=ls[x];y=e[i],i;i=nx[i])
		if(y!=fa[x]) {
			fa[y]=x,deep[y]=deep[x]+1;
			setup(y);
		}
	return ;
}
int depmin(int x,int y) { return deep[x]<deep[y]?x:y; }
int lca(int x,int y) {
	if(x==y) return x;
	if(dfn[x]>dfn[y]) swap(x,y);
	int k=__lg(dfn[y]-dfn[x]);
	return fa[depmin(minn[dfn[x]+1][k],minn[dfn[y]-(1<<k)+1][k])];
}
int LCA(int l,int r) {
	int k=__lg(r-l+1);
	return lca(st[l][k],st[r-(1<<k)+1][k]);
}
int main()
{
	usefile("query");
	int i,j,x,y,l,r,K,ans;
	read(n);
	for(i=1;i<n;++i)
		read(x,y),insert(x,y);
	deep[1]=1,setup(1);
	for(j=1;(1<<j)<=n;++j)
		for(i=1;i+(1<<j)-1<=n;++i)
			minn[i][j]=depmin(minn[i][j-1],minn[i+(1<<j-1)][j-1]);
	for(j=1;(1<<j)<=n;++j)
		for(i=1;i+(1<<j)-1<=n;++i)
			st[i][j]=lca(st[i][j-1],st[i+(1<<j-1)][j-1]);
	
	read(q);
	loop : --q;
	read(l,r,K);
	for(i=l,ans=1;i+K-1<=r;++i)
		ans=max(ans,deep[LCA(i,i+K-1)]);
	printf("%d\n",ans);
	if(q) goto loop;
}
