// {{{ header
#include <bits/stdc++.h>
using namespace std;

using i8   = int8_t;
using u8   = uint8_t;
using i16  = int16_t;
using u16  = uint16_t;
using i32  = int32_t;
using u32  = uint32_t;
using i64  = int64_t;
using u64  = uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;

using f32  = float;
using f64  = double;
using f80  = __float80;
using f128 = __float128;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'000LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

// {{{ util
#define FOR(i, start, end) for(i64 i = (start), i##_end=(end); i < i##_end; ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cc) { return (f)(begin(cc), end(cc), ## __VA_ARGS__); })(c))

bool is_odd (i64 x) { return x % 2 != 0; }
bool is_even(i64 x) { return x % 2 == 0; }

template<typename T> i64 cmp(T x, T y) { return (y<x) - (x<y); }
template<typename T> i64 sgn(T x) { return cmp(x, T(0)); }

template<typename T, typename U>
bool chmax(T& xmax, const U& x) {
    if(xmax < x) {
        xmax = x;
        return true;
    }
    else {
        return false;
    }
}

template<typename T, typename U>
bool chmin(T& xmin, const U& x) {
    if(x < xmin) {
        xmin = x;
        return true;
    }
    else {
        return false;
    }
}

template<typename T>
void RD(T& x) {
    cin >> x;
#ifdef PROCON_LOCAL
    assert(cin);
#endif
}

template<typename T>
void RD(vector<T>& v, i64 n) {
    v.reserve(n);
    REP(_, n) {
        T e; RD(e);
        v.emplace_back(e);
    }
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for(auto first = begin(v), it = first; it != end(v); ++it) {
        if(it != first)
            out << ' ';
        out << *it;
    }
    return out;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1,T2>& p) {
    return out << '(' << p.first << ',' << p.second << ')';
}

void PRINT() {}

template<typename T, typename... TS>
void PRINT(const T& x, const TS& ...args) {
    cout << x;
    if(sizeof...(args)) {
        cout << ' ';
        PRINT(args...);
    }
}

template<typename... TS>
void PRINTLN(const TS& ...args) {
    PRINT(args...);
    cout << '\n';
}

template<typename T>
void DBG_IMPL(i64 line, const char* expr, const T& value) {
#ifdef PROCON_LOCAL
    cerr << "[LINE " << line << "]: ";
    cerr << expr << " = " << value << "\n";
#endif
}

#define DBG(expr) DBG_IMPL(__LINE__, #expr, (expr))
// }}}

// {{{ init
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
#ifdef PROCON_LOCAL
        cerr << fixed << setprecision(IOS_PREC);
#endif
        if(AUTOFLUSH)
            cout << unitbuf;
    }
};
// }}}

//--------------------------------------------------------------------

struct WeightedUnionFind {
    vector<i64> ps_;  // 親ノード。ただし根の場合 -(集合の要素数)
    vector<i64> ws_;  // 親ノードに対する重み(負もOK)。根の場合0

    explicit WeightedUnionFind(i64 n) : ps_(n,-1), ws_(n,0) {}

    i64 root(i64 x) {
        return get<0>(compress(x));
    }

    // 根に対する重み
    i64 weight(i64 x) {
        return get<1>(compress(x));
    }

    // x, y を併合する
    // x に対する y の重みを d とする
    // 併合できたかどうかを返す
    // x, y が元々同一集合に属する場合、d の値によっては矛盾が生じて併合不能
    bool unite(i64 x, i64 y, i64 d) {
        i64 rx, ry, wx, wy;
        tie(rx,wx) = compress(x);
        tie(ry,wy) = compress(y);
        if(rx == ry) return wx + d == wy;

        // 要素数が大きい方を根とする
        i64 kx = -ps_[rx];
        i64 ky = -ps_[ry];
        if(kx < ky) {
            swap(rx, ry);
            swap(wx, wy);
            d *= -1;
        }
        ps_[rx] = -(kx + ky);
        ps_[ry] = rx;
        ws_[ry] = wx - wy + d;
        return true;
    }

    // 経路圧縮
    // (xの根、根に対するxの重み) を返す
    tuple<i64,i64> compress(i64 x) {
        i64 p = ps_[x];
        if(p < 0) return make_tuple(x, 0);

        i64 r,d; tie(r,d) = compress(p);
        ps_[x]  = r;
        ws_[x] += d;
        return make_tuple(r, ws_[x]);
    }
};

i64 N;

void solve() {
    i64 Q; RD(Q);

    WeightedUnionFind wuf(N);
    REP(_, Q) {
        i64 cmd; RD(cmd);
        if(cmd == 0) {
            i64 x,y,z; RD(x); RD(y); RD(z);
            if(!wuf.unite(x,y,z))
                assert(false);
        }
        else if(cmd == 1) {
            i64 x,y; RD(x); RD(y);
            i64 rx = wuf.root(x);
            i64 ry = wuf.root(y);
            if(rx != ry) {
                PRINTLN("?");
            }
            else {
                i64 ans = wuf.weight(y) - wuf.weight(x);
                PRINTLN(ans);
            }
        }
        else {
            assert(false);
        }
    }
}

signed main() {
    RD(N);

    solve();

    return 0;
}



Measured memory_bytes: 4436