#if 0
????????£????????????
#endif

#include <iostream>
#include <cstdio>
using namespace std;
int N,M,A,B,C,D,x1,x2,y1,y2;
int K[32][32];
const int inf=1001001001;
int pay;

int main(){
	//??????Inf??§???????????????????????????
	for(int i=0;i<32;i++)
		for(int j=0;j<32;j++)
			K[i][j]=inf;

	scanf("%d%d",&N,&M);
	for(int i=0;i<M;++i){
		scanf("%d,%d,%d,%d",&A,&B,&C,&D);
		//cerr<<"read "<<A<<' '<<B<<' '<<C<<' '<<D<<endl;
		K[A][B]=C;
		K[B][A]=D;

		for(int i=1;i<N+1;i++){//?????§?????????
    for(int j=1;j<N+1;j++){
      if(K[i][j]==inf){
	cout<<"inf"<<" ";
      }else{
	cout<<K[i][j]<<" ";
      }
    }
    cout<<endl;
  }

	for(int k=1;k<N+1;k++)
		for(int i=1;i<N+1;i++)
			for(int j=1;j<N+1;j++)
				if(K[i][j]>K[i][k]+K[k][j])
					K[i][j]=K[i][k]+K[k][j];

	 for(int l=1;l<N+1;l++){//?????§??????2???
    for(int m=1;m<N+1;m++){
      if(K[l][m]==inf){
	cout<<"inf"<<" ";
      }else{
	cout<<K[l][m]<<" ";
      }
    }
    cout<<endl;
    } 
    cout<<endl;

	scanf("%d,%d,%d,%d", &A, &B, &C, &D);
	pay=K[A][B]+K[B][A];
	cout<<C-D-pay<<endl; 
	}
}