def get_height x
    px, hx = x, 0
    while px != @parent[px][0]
        hx += @parent[px][1]
        px = @parent[px][0]
    end
    return [px, hx]
end

n, q = gets.chomp.split.map(&:to_i)

@parent = []
0.upto(n - 1){|i| @parent[i] = [i, 0]}

q.times{
    command, x, y, z = gets.chomp.split.map(&:to_i)
    px, hx = get_height(x)
    py, hy = get_height(y)

    case command
    when 0
        next if px == py
        if px < py
            @parent[py] = px, hx - hy + z
        else
            @parent[px] = py, hy - hx - z
        end
    when 1
        puts (px != py) ? "?" : hy - hx
    end
}
