#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

struct qnode
{
    int v,c,d;
    qnode(int _v=0,int _c=0,int _d=0):v(_v),c(_c),d(_d){}
    bool operator <(const qnode &r)const
    {
        return c>r.c;
    }
};

struct qwer{
	int to,val,cost,nex;
} a[40010];

int head[10010],now,dis[10010],ans,vis[10010];

int main()
{
	int n,m;
	for (;;)
	{
		cin>>n>>m;
		if (n==0) break;

		memset(head,0,sizeof(head));
		memset(vis,0,sizeof(vis));
		memset(dis,0x3f,sizeof(dis));
		now=1;ans=0;

		for (int i=1;i<=m;i++)
		{
			int q,w,e,r;
			cin>>q>>w>>e>>r;
			a[now].to=w;
			a[now].val=e;
			a[now].cost=r;
			a[now].nex=head[q];
			head[q]=now++;

			a[now].to=q;
			a[now].val=e;
			a[now].cost=r;
			a[now].nex=head[w];
			head[w]=now++;
		}

		priority_queue<qnode> Q;
        while (!Q.empty())Q.pop();
        dis[1]=0;
		Q.push(qnode(1,0,0));
        qnode t;
        while (!Q.empty())
		{
            t=Q.top();
			Q.pop();
			int u=t.v;
			if (vis[u]) continue;
			vis[u]=1;
			ans+=t.d;
			for (int j=head[u];j!=0;j=a[j].nex)
			{
				if (vis[a[j].to]==0 && dis[a[j].to]>dis[u]+a[j].val)
				dis[a[j].to]=dis[u]+a[j].val,Q.push(qnode(a[j].to,dis[a[j].to],a[j].cost));
			}
		}

		cout<<ans<<endl;
	}
	return 0;
}

