require "set"
class MyTree
  def initialize(num_node)
    @nodes = {}
    num_node.times do |i|
      @nodes[i+1] = Node.new(i+1)
    end
    @edges = []
  end

  def calc_dist(n1, n2, ow_color, ow_dist)
    @nodes[n1].calc_dist(@nodes[n2], ow_color, ow_dist)
  end

  def add_edge(n1, n2, color, dist)
    edge = Edge.new(@nodes[n1], @nodes[n2], color, dist)
    @nodes[n1].add_edge(edge)
    @nodes[n2].add_edge(edge)
  end

  class Node
    attr_reader :edges
    def initialize(n1)
      @id = n1
      @edges = []
    end

    def add_edge(edge)
      @edges << edge
    end

    def calc_dist(other_node, ow_color, ow_dist, total_dist = 0, visited = Set.new)
      visited << self
      @edges.each do |edge|
        on = edge.opposite_node(self)
        next if visited.include?(on)
        if on == other_node
          return edge.distance(ow_color, ow_dist) + total_dist
        elsif !on.edges.empty?
          d = on.calc_dist(other_node, ow_color, ow_dist, total_dist + edge.distance(ow_color, ow_dist), visited)
          next if d.nil?
          return d
        end
      end
      nil
    end
  end

  class Edge
    attr_reader :n1, :n2, :color, :dist
    def initialize(n1, n2, color, dist)
      @n1 = n1
      @n2 = n2
      @color = color
      @dist = dist
    end

    def opposite_node(n)
      @n1 == n ? @n2 : @n1
    end

    def distance(overwrite_color, overwrite_dist)
      if @color == overwrite_color
        overwrite_dist
      else
        dist
      end
    end
  end
end

N, Q = gets.chomp.split(" ").map(&:to_i)
tree = MyTree.new(N)
(N-1).times do |i|
  a, b, c, d = gets.chomp.split(" ").map(&:to_i)
  tree.add_edge(a, b, c, d)
end

xyuv = []
Q.times do |j|
  xyuv << gets.chomp.split(" ").map(&:to_i)
end

xyuv.each do |x,y,u,v|
  puts tree.calc_dist(u, v, x, y)
end
