/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-07 20:19:41
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  size_t n = vec.size();
  for (size_t i = 0; i < n; ++i) {
    os << vec[i];
    if (i != n - 1) os << ',';
  }
  os << '}';
  return os;
}
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  os << '{';
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    os << '{' << it->first << ':' << it->second << '}';
    if (it != --mp.end()) os << ',';
  }
  os << '}';
  return os;
}
template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  os << '{';
  for (auto it = st.begin(); it != st.end(); ++it) {
    os << *it;
    if (it != --st.end()) os << ',';
  }
  os << '}';
  return os;
}
template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  size_t n = vec.size();
  for (size_t i = 0; i < n; ++i) is >> vec[i];
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

class UnionFind {
 public:
  UnionFind(int n, int SUM_UNITY = 0) : n_(n), SUM_UNITY_(SUM_UNITY) {
    initialize();
  }

  int root(int x) {
    assert(0 <= x && x < n_);
    if (parent_[x] == -1) {
      return x;
    } else {
      int r = root(parent_[x]);
      diff_weight_[x] += diff_weight_[parent_[x]];
      return parent_[x] = r;
    }
  }

  int weight(int x) {
    assert(0 <= x && x < n_);
    root(x);
    return diff_weight_[x];
  }

  bool same(int x, int y) {
    assert(0 <= x && x < n_ && 0 <= y && y < n_);
    return root(x) == root(y);
  }

  // y is w larger than x
  void unite(int x, int y, int w) {
    assert(0 <= x && x < n_ && 0 <= y && y < n_);
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (rank_[x] < rank_[y]) {
      std::swap(x, y);
      w = -w;
    }
    if (rank_[x] == rank_[y]) ++rank_[x];
    parent_[y] = x;
    diff_weight_[y] = w;
    return;
  }

  int diff(int x, int y) {
    assert(0 <= x && x < n_ && 0 <= y && y < n_);
    return weight(y) - weight(x);
  }

 private:
  const int n_;
  const int SUM_UNITY_;
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> diff_weight_;

  void initialize() {
    parent_.assign(n_, -1);
    rank_.assign(n_, 0);
    diff_weight_.assign(n_, SUM_UNITY_);
  }
};

void DSL_1_B() {
  int n, q;
  cin >> n >> q;
  UnionFind uf(n);
  for (int i = 0; i < q; ++i) {
    int com;
    cin >> com;
    if (com == 0) {
      int x, y, z;
      cin >> x >> y >> z;
      uf.unite(x, y, z);
    } else {
      int x, y;
      cin >> x >> y;
      if (!uf.same(x, y)) {
        cout << '?' << '\n';
      } else {
        cout << uf.diff(x, y) << '\n';
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  DSL_1_B();

  return 0;
}


Measured memory_bytes: 4172