#include <iostream>
#include <type_traits>
#include <vector>
#include <cstdint>
#include <cassert>
#include <numeric>
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_B"

using i32   = int32_t;
using i64   = int64_t;
using u32   = uint32_t;
using u64   = uint64_t;
using uint  = unsigned int;
using usize = std::size_t;
using ll    = long long;
using ull   = unsigned long long;
using ld    = long double;
template<typename T, usize n>
using arr = T (&)[n];
template<typename T, usize n>
using c_arr = const T (&)[n];
template<typename T>
T in()
{
    T v;
    return std::cin >> v, v;
}
template<typename T, typename Uint, usize n, usize i>
T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); }
template<typename T, typename Uint, usize n, usize i>
auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type& szs)
{
    const usize s = (usize)szs[i];
    std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s);
    for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); }
    return ans;
}
template<typename T, typename Uint, usize n>
auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); }
template<typename... Types>
auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; }

template<typename T>
void out(const T& v) { std::cout << v; }
template<typename T>
void out(const std::vector<T>& v)
{
    for (usize i = 0; i < v.size(); i++) {
        if (i > 0) { std::cout << ' '; }
        out(v[i]);
    }
    std::cout << "\n";
}
template<typename T1, typename T2>
void out(const std::pair<T1, T2>& v) { out(v.first), std::cout << ' ', out(v.second); }
template<typename T, typename... Args>
void out(const T& v, const Args... args) { out(v), std::cout << ' ', out(args...); }
template<typename... Args>
void outln(const Args... args) { out(args...), std::cout << '\n'; }
template<typename... Args>
void outel(const Args... args) { out(args...), std::cout << std::endl; }

template<typename Potential>
class pot_unionfind
{
public:
    using potential_type = Potential;
    pot_unionfind(const usize v) : sz{v}, rt(v), comp_sz(v, 1), pot(v, potential_type{}) { std::iota(rt.begin(), rt.end(), 0); }
    usize root_of(const usize a)
    {
        assert(a < sz);
        if (rt[a] == a) { return a; }
        const usize r = root_of(rt[a]);
        return pot[a] += pot[rt[a]], rt[a] = r;
    }
    void unite(usize a, usize b, potential_type w)  // p[b]-p[a]=w
    {
        assert(a < sz), assert(b < sz);
        if (root_of(a) == root_of(b)) { assert(diff_between(a, b) == w); }
        w += pot_of(a), w -= pot_of(b), a = root_of(a), b = root_of(b);
        if (a == b) { return; }
        if (comp_sz[a] < comp_sz[b]) { std::swap(a, b), w = -w; }
        comp_sz[a] += comp_sz[b], rt[b] = a, pot[b] = w;
    }
    usize size_of(const usize a) { return assert(a < sz), comp_sz[root_of(a)]; }
    potential_type diff_between(const usize a, const usize b) { return assert(a < sz), assert(b < sz), assert(root_of(a) == root_of(b)), pot[b] - pot[a]; }
    friend std::ostream& operator<<(std::ostream& os, const pot_unionfind& uf)
    {
        os << "[";
        for (usize i = 0; i < uf.rt.size(); i++) { os << uf.rt[i] << (i + 1 == uf.rt.size() ? "" : ","); }
        return (os << "]\n");
    }

private:
    potential_type pot_of(const usize a) { return assert(a < sz), root_of(a), pot[a]; }
    const usize sz;
    std::vector<usize> rt, comp_sz;
    std::vector<potential_type> pot;
};
int main()
{
    const auto n = in<usize>();
    const auto q = in<usize>();
    pot_unionfind<int> uf(n);
    for (usize i = 0; i < q; i++) {
        const auto c = in<usize>();
        if (c == 0) {
            const auto u = in<usize>();
            const auto v = in<usize>();
            const auto d = in<ll>();
            uf.unite(u, v, d);
        } else {
            const auto u = in<usize>();
            const auto v = in<usize>();
            if (uf.root_of(u) == uf.root_of(v)) {
                outln(uf.diff_between(u, v));
            } else {
                outln("?");
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4684