#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <array>
#include <tuple>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

template <typename F>
class fix_point: F {
public:
  explicit constexpr fix_point(F&& f) noexcept: F(std::forward<F>(f)) {}

  template <typename... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return F::operator ()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) make_fix_point(F&& f) noexcept {
  return fix_point<F>{std::forward<F>(f)};
}

template <typename WeightType>
class weighted_edge {
public:
  using size_type = size_t;
  using weight_type = WeightType;

protected:
  size_type M_src, M_dst;
  weight_type M_weight;

public:
  weighted_edge() = default;
  weighted_edge(weighted_edge const&) = default;
  weighted_edge(weighted_edge&&) = default;

  weighted_edge(size_type s, size_type d, weight_type w):
    M_src(s), M_dst(d), M_weight(w)
  {}

  weighted_edge& operator =(weighted_edge const&) = default;
  weighted_edge& operator =(weighted_edge&&) = default;

  bool operator <(weighted_edge const& other) const {
    if (M_weight < other.M_weight) return true;
    if (other.M_weight < M_weight) return false;
    if (M_src != other.M_src) return M_src < other.M_src;
    return M_dst < other.M_dst;
  }

  size_type source() const { return M_src; }
  size_type target() const { return M_dst; }
  size_type weight() const { return M_weight; }
};

template <typename WeightType>
class colored_weighted_edge: public weighted_edge<WeightType> {
public:
  using size_type = size_t;
  using weight_type = WeightType;
  using color_type = size_type;

protected:
  color_type M_color;

public:
  colored_weighted_edge() = default;
  colored_weighted_edge(colored_weighted_edge const&) = default;
  colored_weighted_edge(colored_weighted_edge&&) = default;

  colored_weighted_edge(size_type s, size_type d, color_type c, weight_type w):
    weighted_edge<WeightType>(s, d, w), M_color(c)
  {}

  colored_weighted_edge& operator =(colored_weighted_edge const&) = default;
  colored_weighted_edge& operator =(colored_weighted_edge&&) = default;

  bool operator <(colored_weighted_edge const& other) const {
    if (this->M_weight < other.M_weight) return true;
    if (other.M_weight < this->M_weight) return false;
    if (M_color != other.M_color) return M_color < other.M_color;
    if (this->M_src != other.M_src) return this->M_src < other.M_src;
    return this->M_dst < other.M_dst;
  }

  size_type color() const { return M_color; }
};

struct directed_tag {};
struct undirected_tag {};

template <typename Edge, typename Tag>
class adjacency_list {};

template <typename Edge>
class adjacency_list<Edge, undirected_tag> {
public:
  using size_type = size_t;
  using edge_type = Edge;
  using weight_type = typename Edge::weight_type;

private:
  std::vector<std::vector<edge_type>> M_g;

public:
  adjacency_list() = default;
  adjacency_list(adjacency_list const&) = default;
  adjacency_list(adjacency_list&&) = default;
  adjacency_list(size_type n): M_g(n) {}

  template <typename... Args>
  void emplace(size_type src, size_type dst, Args... args) {
    M_g[src].emplace_back(src, dst, args...);
    M_g[dst].emplace_back(dst, src, args...);
  }

  size_type size() const { return M_g.size(); }
  std::vector<edge_type> const& operator [](size_type i) const { return M_g[i]; }
};

template <typename Edge>
auto euler_tour(adjacency_list<Edge, undirected_tag> const& g, size_t r) {
  // .first[i]: i-th edge
  // .second[0][v]: index of tour (without r) that enters vertex v
  // .second[1][v]: index of tour that leaves vertex v
  size_t n = g.size();
  std::vector<Edge> res_first;
  std::array<std::vector<size_t>, 2> res_second;
  res_second[0] = res_second[1] = std::vector<size_t>(n);
  size_t i = 0;
  make_fix_point([&](auto dfs, size_t v, size_t p) -> void {
      Edge ep;
      for (auto const& e: g[v]) {
        if (e.target() == p) {
          ep = e;
          continue;
        }
        res_second[0][e.target()] = i++;
        res_first.push_back(e);
        dfs(e.target(), e.source());
      }
      if (v != r) {
        res_second[1][v] = i++;
        res_first.push_back(ep);
      }
  })(r, -1);
  return std::make_pair(res_first, res_second);
}

template <class Tp, class Compare = std::less<Tp>>
class sparse_table {
public:
  using size_type = size_t;
  using value_type = Tp;
  using value_compare = Compare;

private:
  std::vector<std::vector<value_type>> c;
  value_compare comp;

public:
  sparse_table() = default;
  sparse_table(sparse_table const&) = default;
  sparse_table(sparse_table&&) = default;

  template <class InputIt>
  sparse_table(InputIt first, InputIt last,
               value_compare comp = value_compare()):
    c(1, std::vector<value_type>(first, last)), comp(comp)
  {
    size_type n = c[0].size();
    for (size_type i = 1, ii = 1; c.back().size() > ii; (++i, ii <<= 1)) {
      c.emplace_back();
      c.back().reserve(n - ii);
      for (size_type j = ii; j < c[i-1].size(); ++j)
        c[i].push_back(std::min(c[i-1][j], c[i-1][j-ii], comp));
    }
  }

  sparse_table& operator =(sparse_table const&) = default;
  sparse_table& operator =(sparse_table&&) = default;

  value_type get(size_type l, size_type r) const {
    assert(l < r);
    size_type e = 63 - __builtin_clzll(r-l);
    r -= (1_zu << e) - 1;
    return std::min(c[e][l], c[e][r-1], comp);
  }
};

class tree_lowest_common_ancestor {
public:
  using size_type = size_t;

private:
  std::vector<size_type> M_e;
  sparse_table<std::pair<size_type, size_type>> M_st;

  template <typename Graph>
  void M_dfs(Graph const& g, size_type v, size_type p, size_type d0,
             std::vector<std::pair<size_type, size_type>>& d) {

    M_e[v] = d.size();
    d.emplace_back(d0, v);
    for (auto const& e: g[v]) {
      if (e.target() == p) continue;
      M_dfs(g, e.target(), v, d0+1, d);
      d.emplace_back(d0, v);
    }
  }

public:
  tree_lowest_common_ancestor() = default;
  tree_lowest_common_ancestor(tree_lowest_common_ancestor const&) = default;
  tree_lowest_common_ancestor(tree_lowest_common_ancestor&&) = default;

  template <typename Graph>
  tree_lowest_common_ancestor(Graph const& g, size_type r): M_e(g.size()) {
    std::vector<std::pair<size_type, size_type>> d;
    M_dfs(g, r, -1, 0, d);
    M_st = sparse_table<std::pair<size_type, size_type>>(d.begin(), d.end());
  }

  size_type operator ()(size_type u, size_type v) const {
    size_type x, y;
    std::tie(x, y) = std::minmax(M_e[u], M_e[v]);
    return M_st.get(x, y+1).second;
  }
};

template <typename Tree>
auto tree_distance(Tree const& g, size_t s) {
  using weight_type = typename Tree::weight_type;
  std::vector<weight_type> res(g.size());
  make_fix_point([&](auto dfs, size_t v, size_t p) -> void {
      for (auto const& e: g[v]) {
        size_t nv = e.target();
        if (nv == p) continue;
        res[nv] = res[v] + e.weight();
        dfs(nv, v);
      }
  })(s, -1);
  return res;
}

int main() {
  size_t n, q;
  scanf("%zu %zu", &n, &q);

  adjacency_list<colored_weighted_edge<intmax_t>, undirected_tag> g(n);
  for (size_t i = 1; i < n; ++i) {
    size_t a, b, c;
    intmax_t d;
    scanf("%zu %zu %zu %jd", &a, &b, &c, &d);
    --a, --b, --c;
    g.emplace(a, b, c, d);
  }

  std::vector<colored_weighted_edge<intmax_t>> es;
  std::array<std::vector<size_t>, 2> vi;
  std::tie(es, vi) = euler_tour(g, 0);
  std::vector<intmax_t> c0;
  std::vector<std::vector<size_t>> is(n);
  for (auto const& e: es)
    c0.push_back(e.weight());

  for (size_t j = 1; j < n; ++j) {
    size_t i = vi[0][j];
    is[es[i].color()].push_back(i);
  }
  for (size_t j = 1; j < n; ++j) {
    size_t i = vi[1][j];
    is[es[i].color()].push_back(i);
    c0[i] = -c0[i];
  }
  for (size_t i = 0; i < n; ++i) {
    std::sort(is[i].begin(), is[i].end());
  }

  std::vector<std::vector<intmax_t>> cs(n);
  std::vector<std::vector<intmax_t>> cn(n);
  for (size_t i = 0; i < n; ++i) {
    cs[i].push_back(0);
    cn[i].push_back(0);
    for (auto j: is[i]) {
      cs[i].push_back(cs[i].back() + c0[j]);
      cn[i].push_back(cn[i].back() + ((c0[j] > 0)? +1: -1));
    }
    cs[i].push_back(0);
    cn[i].push_back(0);
  }

  auto dist = tree_distance(g, 0);
  tree_lowest_common_ancestor lca(g, 0);

  auto f = [&](size_t x, intmax_t y, size_t v) -> intmax_t {
    if (v == 0) return 0;
    if (is[x].empty()) return 0;
    auto it = std::upper_bound(is[x].begin(), is[x].end(), vi[0][v]);
    if (it == is[x].begin()) return 0;
    size_t i = it - is[x].begin();
    return y * cn[x][i] - cs[x][i];
  };

  for (size_t i = 0; i < q; ++i) {
    size_t x, u, v;
    intmax_t y;
    scanf("%zu %jd %zu %zu", &x, &y, &u, &v);
    --x, --u, --v;

    size_t w = lca(u, v);
    intmax_t res = dist[u] + dist[v] - 2*dist[w];
    res += f(x, y, u) + f(x, y, v) - 2*f(x, y, w);

    printf("%jd\n", res);
  }
}


Measured memory_bytes: 105476