module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n q ->
  let es = Array.make n [] in
  for i = 0 to n - 2 do
    Scanf.scanf "%d %d %d %d\n" @@ fun a b c d ->
      es.(a - 1) <- (b - 1, c, d) :: es.(a - 1);
      es.(b - 1) <- (a - 1, c, d) :: es.(b - 1)
  done;
  let dist = Array.make n (-1) in
  let count_colors = Array.make n IntMap.empty in
  let acc_colors = Array.make n IntMap.empty in
  let parent = Array.make_matrix 17 n 0 in
  let rec visit c cd d u v =
    if 0 <= dist.(v) then ()
    else begin
      dist.(v) <- d;
      parent.(0).(v) <- u;
      acc_colors.(v) <- cd;
      count_colors.(v) <- c;
      List.iter (fun (u, c', d') ->
        visit
          (IntMap.add c'
            (1 +
              try IntMap.find c' c
              with Not_found -> 0) c)
          (IntMap.add c'
            (d' +
              try IntMap.find c' cd
              with Not_found -> 0) cd)
          (d + d') v u) es.(v)
    end in
  visit IntMap.empty IntMap.empty 0 0 0;
  for i = 1 to 16 do
    for v = 0 to n - 1 do
      parent.(i).(v) <- parent.(i - 1).(parent.(i - 1).(v))
    done
  done;
  let rec lca u v = function
    | 0 ->
        if parent.(0).(u) = parent.(0).(v)
        then parent.(0).(u)
        else begin
          assert (parent.(1).(u) = parent.(1).(v));
          parent.(1).(u)
        end
    | i ->
        ( if parent.(i).(u) = parent.(i).(v)
          then lca u v
          else lca (parent.(i).(u)) (parent.(i).(u)) ) (i - 1) in
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d %d %d\n" @@ fun x y u v ->
      let w = lca (u - 1) (v - 1) 16 in
      Printf.printf "%d\n" @@
      (dist.(u - 1) - (try IntMap.find x acc_colors.(u - 1) with Not_found -> 0) + y * (try IntMap.find x count_colors.(u - 1) with Not_found -> 0))
      + (dist.(v - 1) - (try IntMap.find x acc_colors.(v - 1) with Not_found -> 0) + y * (try IntMap.find x count_colors.(v - 1) with Not_found -> 0))
      - 2 * (dist.(w) - (try IntMap.find x acc_colors.(w) with Not_found -> 0) + y * (try IntMap.find x count_colors.(w) with Not_found -> 0))
  done





