#include <iostream>
#include <cassert>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
//INSERT ABOVE HERE

template<typename T>
class Deque{
public:
  T *val;
  int sz;
  int length;
  int head, tail;
  
  Deque(){sz = 0, length = 0, val = new T[0];}
  Deque(int size, T init = T()){
    length = 1;
    while(length < size) length *= 2;
    val = new T[length];
    sz = size;
    head = 0;
    tail = 0;
    for(int i=0;i<size;i++) val[tail++] = init;
  }
  
  Deque(const Deque &t){
    sz = t.size();
    length = 1;
    while(length < sz) length *= 2;
    val = new T[length];
    head = 0;
    tail = 0;
    for(int i=0;i<sz;i++) val[tail++] = t[i];
  }

  ~Deque(){
    delete [] val;
  }
  
  T& operator [] (int i){assert(0 <= i && i < sz);return val[(head + i)%length];}
  T& operator [] (int i)const{assert(0 <= i && i < sz);return val[(head + i)%length];}
  int size()const{return sz;}
  int empty()const{return sz == 0;}

  void increaseMemory(){
    int length_ = length;
    
    length = length * 2;
    if(length == 0) length = 1;
    T *val2 = new T[length];
    for(int i=0;i<sz;i++) val2[i] = val[(head + i)%length_];
    head = 0;
    tail = sz;
    delete [] val;
    val = val2;
  };
  
  void push_back(T v){
    if(sz == length) increaseMemory();
    sz++;
    val[tail++] = v;
    if(tail == length) tail = 0;
  }
  
  void push_front(int v){
    if(sz == length) increaseMemory();
    sz++;
    head--;
    if(head == -1) head = length - 1;
    val[head] = v;
  }

  void pop_back(){
    assert(sz > 0);
    sz--;
    tail--;
    if(tail == -1) tail = length - 1;
  }
  
  void pop_front(){
    assert(sz > 0);
    sz--;
    head++;
    if(head == length) head = 0;
  }
};
template <typename T>
using vector = Deque<T>;

class WeightedUnionFind{
public:
  int V;
  vector<int> par, rnk, diff, sz;
  WeightedUnionFind():V(-1){}
  WeightedUnionFind(int V):V(V),par(V),rnk(V,0),diff(V,0),sz(V,1){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x] == x) return x;
    int p = find(par[x]);
    diff[x] = diff[x] + diff[ par[x] ];
    return par[x] = p;
  }

  //頂点xは頂点yよりもz大きい
  void relate(int x,int y,int z){
    int sx = x, sy = y;
    x = find(x), y = find(y);
    if(x == y) assert(getDiff(sx,sy) == z);
    if(x == y)return;
    
    if(rnk[x] < rnk[y]) {
      par[x] = y;
      sz[y] += sz[x];
      diff[x] = z + (-diff[sx] + diff[sy]);
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      diff[y] = -z + (diff[sx] - diff[sy]);
      if(rnk[x]==rnk[y])rnk[x]++;
    }
  }

  int getDiff(int u,int v){
    assert(same(u,v));
    return diff[u] - diff[v];
  }
  
  bool same(int x,int y){return find(x)==find(y);}
  int size(int x){return sz[find(x)];}
  
};


signed main(){
  int n;
  std::cin>>n;
  WeightedUnionFind wuf(n);
  
  int q;
  std::cin>>q;
  while(q--){
    int cmd, x, y, z;
    std::cin>>cmd >> y >> x;
    if(cmd == 0){
      std::cin>>z;
      wuf.relate(x,y,z);
    }
    if(cmd == 1){
      if(!wuf.same(x, y)) std::cout<<"?"<<std::endl;
      else std::cout<<wuf.getDiff(x, y)<<std::endl;
    }
  }
  return 0;
}



Measured memory_bytes: 4384