#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long i64;

const int SIZE = 5e5+5;

/*
AFO
it = journey
it can be painful awesome of good
if it's painful, then it's awesome
if it's awesome, then it's good
how many solution can the journey be?:)
*/

int n, q;
vector< int > g[SIZE];
int btm[SIZE], dfn[SIZE], tick, dep[SIZE];
int od[SIZE], st1[20][SIZE], st2[20][SIZE];

void dfs(int u, int f) {
	dep[u] = dep[f] + 1;
	dfn[u] = btm[u] = ++tick;
	for (const int v : g[u]) {
		if (v == f) continue;
		dfs(v, u);
		btm[u] = max(btm[u], dfn[v]);
	}
}

bool cmp(int x, int y) {
	if(dep[x] == dep[y]) return dfn[x] < dfn[y];
	else return dep[x] < dep[y];
}

int qry1(int l, int r) {
	int k = log(r - l + 1) / log(2);
	return min(st1[k][l], st1[k][r - (1 << k) + 1]);
}

int qry2(int l, int r) {
	int k = log(r - l + 1) / log(2);
	return min(st2[k][l], st2[k][r - (1 << k) + 1]);
}

int Find(int l, int r, int mn, int mx) {
	int res = 0;
	while (l <= r) {
		int mid = l + r >> 1;
		if (dfn[mid] <= mn && mx <= btm[mid]) {
			res = mid;
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}
	return res;
}

int main() {
	#ifdef fio
	freopen("../test.in","r",stdin);
	#else
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	#endif
	scanf("%d%d",&n,&q);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; ++i) {
		st1[0][i] = st2[0][i] = dfn[i];
	}
	for (int i = 1; (1 << i) <= n; ++i) {
		for (int j = 1; j + (1 << i) - 1 <= n; ++j) {
			st1[i][j] = min(st1[i - 1][j], st1[i - 1][j + (1 << (i - 1))]);
			st2[i][j] = max(st2[i - 1][j], st2[i - 1][j + (1 << (i - 1))]);
		}
	}
	for (int i = 1; i <= n; ++i) {
		od[i] = i;
	}
	sort(od + 1, od + 1 + n, cmp);
	while (q--) {
		int l, r, k;
		scanf("%d%d%d",&l,&r,&k);
		if (k == r - l + 1) {
			printf("%d\n", Find(1, n, qry1(l, r), qry2(l, r)));
		} else {
			printf("1\n");
		}
	}
	return 0;
}
