#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

class UnionFind
{
    private:
        vl parents;
        vl rank;
        vl diff_weight;

    public:
        UnionFind(ll n) {
            for (ll i = 0; i < n; i++) {
                parents.push_back(i);
            }
            rank.resize(n, 1);
            diff_weight.resize(n, 0);
        }

        ll weight(ll a) {
            root(a);
            return diff_weight[a];
        }

        ll diff(ll a, ll b) {
            return diff_weight[a] - diff_weight[b];
        }

        ll root(ll a) {
            if (parents[a] == a) return a;
            ll r = root(parents[a]);

            diff_weight[a] += diff_weight[parents[a]];
            parents[a] = r;
            return r;
        }

        ll same(ll a, ll b) {
            return root(a) == root(b);
        }

        bool unite(ll a, ll b, ll d) {
            ll ra = root(a);
            ll rb = root(b);
            if (ra == rb) return false;

            if (rank[ra] < rank[rb]) {
                rank[rb] += rank[ra];
                diff_weight[ra] = d - diff_weight[a] + diff_weight[b];
                parents[ra] = rb;
            } else {
                rank[ra] += rank[rb];
                diff_weight[rb] = diff_weight[a] - diff_weight[b] - d;
                parents[rb] = ra;
            }
            return false;
        }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    UnionFind uni(N);
    rep(i, Q) {
        int C, X, Y, Z;
        cin >> C;
        if (C == 0) {
            cin >> X >> Y >> Z;
            uni.unite(X, Y, Z);
        } else {
            cin >> X >> Y;
            if (uni.same(X, Y)) {
                cout << (uni.diff(X, Y)) << endl;
            } else {
                cout << '?' << endl;
            }
        }
    }
}
