#include <bits/stdc++.h>
#include "infection.h"
#pragma GCC optimize ("unroll-loops")

const int NMAX = 15e4;

using namespace std;

vector<int> Tree[NMAX + 5];
int cat_timp[NMAX + 5];
int tin[NMAX + 5], tout[NMAX + 5], dep[NMAX + 5], par[NMAX + 5];
int infected[NMAX + 5], day[NMAX + 5], s[NMAX + 5], t[NMAX + 5], n, m, timer;
map<pair<int, int>, vector<int>> ev;

void dfs(int nod, int p = 0) {
    dep[nod] = dep[p] + 1;
    tin[nod] = ++timer;
    par[nod] = p;
    for (auto &son : Tree[nod]) {
        if (son == p) continue;
        dfs(son, nod);
    }
    tout[nod] = timer;
}

bool is_anc(int u, int v) {
    ///l <= st && dr <= r
    return tin[u] <= tin[v] && tout[v] <= tout[u];
}

vector<int> get_path(int u, int v) {
    int lca = 1;
    for (int nod = 1; nod <= n; ++nod) {
        if (is_anc(nod, u) && is_anc(nod, v) && dep[nod] > dep[lca])
            lca = nod;
    }

    vector<int> u_lca;
    vector<int> lca_v;

    if (dep[u] > dep[lca]) {
        while (u != lca) {
            u_lca.push_back(u);
            u = par[u];
        }
    }

    u_lca.push_back(lca);
    if (dep[v] > dep[lca]) {
        while (v != lca) {
            lca_v.push_back(v);
            v = par[v];
        }
    }

    vector<int> path = u_lca;
    reverse(lca_v.begin(), lca_v.end());
    for (auto &it : lca_v)
        path.push_back(it);

    return path;
}

std::vector<int> solve( std::vector<std::pair<int, int>> R, std::vector<long long> D, std::vector<int> S, std::vector<int> T, std::vector<bool> I) {
    n = R.size() + 1;
    m = D.size();

    for (auto &[u, v] : R) {
        ++u, ++v;
        Tree[u].push_back(v);
        Tree[v].push_back(u);
    }

    for (int i = 0; i < m; ++i) {
        s[i + 1] = S[i] + 1;
        t[i + 1] = T[i] + 1;
        day[i + 1] = D[i];
        infected[i + 1] = I[i];
    }

    timer = 0;
    dfs(1);
    //
    // auto ret = get_path(s[2], t[2]);
    // for (auto &it : ret)
    //     cout << it << ' ';
    // cout << '\n';

    ev.clear();
    for (int i = 1; i <= m; ++i){
        int cur = day[i];
        for (auto &u : get_path(s[i], t[i])) {
            ev[{cur, u}].push_back(i);
            ++cur;
        }
    }

    fill(cat_timp + 1, cat_timp + m + 1, 0LL);
    for (auto &[info, who] : ev) {
        auto [day, city] = info;

        bool infectati = false;
        for (auto &it : who)
            infectati |= infected[it];

        for (auto &it : who) {
            infected[it] |= infectati;
            if (infected[it])
                ++cat_timp[it];
        }
    }

    vector<int> ans;
    for (int i = 1; i <= m; ++i)
        ans.push_back(cat_timp[i]);

    return ans;
}

#ifndef EVAL

#include "infection.h"
#include <vector>
#include <iostream>

signed main() {
    int n, m;

    std::cin >> n;
    std::cin >> m;

    std::vector<std::pair<int, int>> edges = {};
    std::vector<long long> day;
    std::vector<int> start;
    std::vector<int> target;
    std::vector<bool> infected;

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        edges.emplace_back(u, v);
    }

    for (int i = 0; i < m; i++) {
        long long _d, _s, _t, _i;
        std::cin >> _d >> _s >> _t >> _i;
        day.push_back(_d);
        start.push_back(_s);
        target.push_back(_t);
        infected.push_back(_i);
    }

    const auto ans = solve(edges, day, start, target, infected);
    for (const auto it : ans) {
        std::cout << it << std::endl;
    }

    return 0;
}

#endif