#include <bits/stdc++.h>
#include "infection.h"

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;
vector<int> u_lca;
vector<int> lca_v;
map<pair<int, int>, vector<int>> ev;

namespace HLD {
    vector<int> T[NMAX + 5];
    int dep[NMAX + 5];
    int pr[NMAX + 5];
    int sz[NMAX + 5];
    pair<int, int> mx[NMAX + 5];

    int head[NMAX + 5];
    int id[NMAX + 5];
    int N;
    int cid;

    inline void add_edge(int u, int v) {
        T[u].push_back(v);
        T[v].push_back(u);
        N = max({N, u, v});
    }

    void calc_sz(int nod, int p = 0) {
        dep[nod] = dep[p] + 1;
        pr[nod] = p;
        sz[nod] = 1;
        mx[nod] = make_pair(0, -1);
        for (auto &son : T[nod]) {
            if (son == p) continue;
            calc_sz(son, nod);
            sz[nod] += sz[son];
            mx[nod] = max(mx[nod], make_pair(sz[son], son));
        }
    }

    void decomp(int nod, int p, int h) {
        head[nod] = h;
        id[nod] = ++cid;

        if (mx[nod].second != -1)
            decomp(mx[nod].second, nod, h);

        for (auto &son : T[nod]) {
            if (son == p || son == mx[nod].second) continue;
            decomp(son, nod, son);
        }
    }

    void init() {
        calc_sz(1);
        decomp(1, 0, 1);
    }

    int lca(int a, int b) {
        while (head[a] != head[b]) {
            if (dep[head[a]] < dep[head[b]])
                swap(a, b);
            a = pr[head[a]];
        }

        if (id[a] > id[b]) swap(a, b);
        return a;
    }

    int dist(int u, int v) {
        return dep[u] + dep[v] - 2 * dep[lca(u, v)];
    }

    void clear() {
        fill(T + 1, T + N + 1, vector<int>());
        N = cid = 0;
    }
};

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

vector<int> get_path(int u, int v) {
    int lca = HLD::lca(u, v);
    u_lca.clear();
    lca_v.clear();

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

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

    vector<int> path;
    path.swap(u_lca);
    for (int i = lca_v.size() - 1; i >= 0; --i)
        path.push_back(lca_v[i]);

    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);
        HLD::add_edge(u, v);
    }

    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;
    HLD::init();
    dfs(1);

    ev.clear();
    lca_v.reserve(n);
    u_lca.reserve(n);
    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;
    HLD::clear();
    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