#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <cassert>
#define PII pair<int, int>
#define x first
#define y second
#define For(i, l, r) for(int i = l; i <= r; i ++)
#define Rep(i, l, r) for(int i = l; i >= r; i --)
using namespace std;
bool START;
void in(int &x)
{
char c = getchar(); int op = 1;
while(c > '9' || c < '0') op *= (c == '-' ? -1 : 1), c = getchar();
for(x = 0; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0'; x *= op;
}
#define pc putchar
int wc, wr[110];
void write(int x)
{
if(!x) {pc('0'); return ;}
if(x < 0) pc('-'), x = -x;
wc = 0; while(x) wr[++ wc] = x % 10, x /= 10;
while(wc --) pc(wr[wc + 1] + '0');
}
const int N = 1e6 + 50;
int n, m, Ans[N], dep[N], sz[N], dfn[N], hhk, ed[N], pos[N], Fa[N];
vector<int> G[N];
void Pre(int u, int pa)
{
sz[u] = 1; dfn[u] = ++ hhk; pos[dfn[u]] = u;
dep[u] = dep[pa] + 1;
for(int v : G[u]) if(v != pa)
{
Fa[v] = u;
Pre(v, u);
sz[u] += sz[v];
}
ed[u] = dfn[u] + sz[u] - 1;
}
namespace BIT
{
int c[N];
void init() {For(i, 0, n) c[i] = 0;}
void upd(int x, int y)
{
while(x) c[x] = max(c[x], y), x -= x & (-x);
}
void clear(int x)
{
while(x) c[x] = 0, x -= x & (-x);
}
int qmax(int x)
{
int s = 0; while(x <= n) s = max(s, c[x]), x += x & (-x); return s;
}
}
vector<PII> q1[N], is[N];
set<PII> se[N];
int cnt;
struct node
{
int l, r, val, op, id;
}p[N << 2], pp[N << 2];
PII zan[N]; int zz;
void Dfs(int u, int pa)
{
se[u].insert({u, u});
p[++ cnt] = (node){u, u, dep[u]};
for(int v : G[u]) if(v != pa)
{
Dfs(v, u);
if(se[u].size() < se[v].size()) swap(se[u], se[v]);
for(PII E : se[v])
{
set<PII>::iterator it = se[u].upper_bound({E.y + 1, N + N});
int L = E.x, R = E.y;
if(it != se[u].begin())
{
zz = 0;
do{
it --;
if(it -> y >= L - 1)
{
L = min(L, it -> x);
R = max(R, it -> y);
zan[++ zz] = *it;
}
else break;
}while(it != se[u].begin());
For(i, 1, zz) se[u].erase(zan[i]);
se[u].insert({L, R});
if(L < E.x || R > E.y) p[++ cnt] = (node){L, R, dep[u]};
}
else se[u].insert({L, R});
}
}
}
void solve1()
{
BIT::init();
For(i, 1, n)
{
for(PII E : is[i]) BIT::upd(E.x, E.y);
for(PII E : q1[i]) Ans[E.y] = max(Ans[E.y], BIT::qmax(E.x));
}
}
void CDQ(int l, int r)
{
if(l >= r) return ;
int mid = (l + r) >> 1;
CDQ(l, mid); CDQ(mid + 1, r);
int x = l, y = mid + 1, z = l - 1;
while(x <= mid || y <= r)
{
if((x <= mid && ((p[x].l > p[y].l) || (p[x].l == p[y].l && p[x].op < p[y].op))) || (y > r))
{
if(p[x].op == 1) BIT::upd(p[x].r - p[x].l + 1, p[x].val);
pp[++ z] = p[x];
x ++;
}
else
{
if(p[y].op == 2) Ans[p[y].id] = max(Ans[p[y].id], BIT::qmax(p[y].val));
pp[++ z] = p[y];
y ++;
}
}
For(i, l, mid) if(p[i].op == 1) BIT::clear(p[i].r - p[i].l + 1);
For(i, l, r) p[i] = pp[i];
}
bool ENDPOS;
int main()
{
freopen("query.in", "r", stdin);
freopen("query.out", "w", stdout);
in(n);
For(i, 2, n)
{
int u, v; in(u); in(v);
G[u].push_back(v); G[v].push_back(u);
}
Pre(1, 0);
Dfs(1, 0);
in(m);
For(i, 1, cnt) p[i].op = 1;
For(i, 1, cnt) is[p[i].l].push_back({p[i].r, p[i].val});
For(qid, 1, m)
{
int l, r, k, ans = 0; in(l); in(r); in(k);
p[++ cnt] = (node){l, r, k, 2, qid};
q1[l].push_back({l + k - 1, qid});
q1[r - k + 1].push_back({r, qid});
Ans[qid] = ans;
}
solve1();
sort(p + 1, p + cnt + 1, [](node a, node b) {return a.r != b.r ?a.r < b.r : a.op < b.op;});
BIT::init();
CDQ(1, cnt);
For(i, 1, m) write(Ans[i]), pc('\n');
cerr << (&ENDPOS - &START) * 1.0 / 1024 / 1024 << endl;
return 0;
}