#include<stdio.h>
#include<stdlib.h>

int main(){
    int i, j;
    int n, q;
    int x, y, z;
    int *a;
    int com;

    scanf("%d%d", &n, &q);
    a=malloc(sizeof(int) * n * n);
    for(i=0;i<n*n;i++)a[i]=-1;

    for(i=0;i<q;i++){
        scanf("%d", &com);
        if(com==0){
            scanf("%d%d%d", &x, &y, &z);
            a[y*n+x]=z;
            for(j=0;j<n;j++){
                if(a[y*n+j]!=-1 && j!=x){
                    if(a[y*n+j]>a[y*n+x])a[x*n+j]=a[y*n+j]-a[y*n+x];
                    else a[j*n+x]= a[y*n+x]-a[y*n+j];
                }
                if(a[x*n+j]!=-1)a[y*n+j]=a[y*n+x]+a[x*n+j];
                if(a[j*n+x]!=-1 && j!=y){
                    if(a[j*n+x]>a[y*n+x])a[j*n+y]=a[j*n+x]-a[y*n+x];
                    else a[y*n+j]=a[y*n+x]-a[j*n+x];
                }
                if(a[j*n+y]!=-1)a[j*n+x]=a[y*n+x]+a[j*n+y];
            }
        }else{
            scanf("%d%d", &x, &y);
            if(a[y*n+x]==-1)printf("?\n");
            else printf("%d\n", a[y*n+x]);
        }
    }
    free(a);
    return 0;
}
