#include <iostream>
using namespace std;

#include <vector>
template<class T>struct UnionFind {
  vector<int> parent, sz;
  vector<T> _diff;
  UnionFind(int n) {
    parent.resize(n, -1);
    sz.resize(n, 1);
    _diff.resize(n, 0); // 親との差
  }
  int root(int x) {
    if (parent[x] == -1)
      return x;
    int r = root(parent[x]);
    _diff[x] += _diff[parent[x]];
    return parent[x] = r;
  }
  T weight(int x) {
    root(x);
    return _diff[x];
  }
  void merge(int x, int y, T w) {
    // weight(x) = weight(y) + w;
    // yが親
    if (root(x) == root(y))
      return;
    T d = weight(y) - weight(x) + w;
    x = root(x); y = root(y);
    parent[x] = y;
    sz[y] += sz[x];
    _diff[x] = d;
    return;
  }
  T diff(int x, int y) {
    return weight(y) - weight(x);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sz[root(x)];
  }
};

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int main() {
  int n, q; cin >> n >> q;
  UnionFind<int> T(n);

  rep(i, q) {
    int com, x, y;
    ins(com, x, y);
    if (com == 0) {
      int in(z);
      T.merge(y, x, z);
    } else if (com == 1) {
      if (T.same(x, y))
        cout << T.diff(x, y) << endl;
      else
        cout << "?" << endl;
    }
  }
  return 0;
}

