#define DEBUG
#ifdef DEBUG
#include "infection.h"
#endif
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>

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
) {

    std::vector<std::vector<int>> adj(1e5+5);

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


    std::queue< std::pair< std::pair<int, int>, std::vector<std::pair<int, bool> >> > q;

    for (int i = 0; i < adj.size(); i++) {
        std::vector<std::pair<int, bool>> v = {std::make_pair(S[i], T[i])};
        q.push(
               {
                   std::make_pair(
                                  std::make_pair(i, S[i]),
                                  v
                                  )
               }
               );
    }

    std::vector<std::vector<bool>> visited(S.size(), std::vector<bool>(adj.size(), false));
    std::vector<std::vector<std::pair<int, bool>>> paths(S.size() + 1);
    while (!q.empty()) {
        std::pair<std::pair<int, int>, std::vector<std::pair<int, bool>>> p = q.front();
        q.pop();
        if (visited[p.first.first][p.first.second])
            continue;

        visited[p.first.first][p.first.second] = true;

        
        for (auto v : adj[p.first.second]) {
            if (v == T[p.first.first] && paths[p.first.first].size() == 0) {
                paths[p.first.first] = p.second;
                paths[p.first.first].push_back(std::make_pair(v, p.second[0].second));
                break;
            } else {
                p.second.push_back(std::make_pair(v, p.second[0].second));
                q.push(std::make_pair(std::make_pair(p.first.first, v), p.second));
                p.second.pop_back();
            }
        }
        std::cout << "OLA" << std::endl;
    }

    for (int i = 0; i < paths.size(); i++) {
        for (int j = 0; j < paths[i].size(); i++) {
            if (paths[i][j].second) {
                for (int k = 0; k < paths[i].size(); i++) {
                    if (paths[i][j].first == paths[i][k].first) {
                        paths[i][k].second == true;
                    }
                }
            }
        }
    }

    for (int i = 0; i < paths.size(); i++) {
        for (int j = 0; j < paths.size(); j++) {
            if (paths[i][j].second) {
                std::cout << j << std::endl;
                break;
            }
        }
    }




    return {};
}
#ifndef DEBUG
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
