#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std; typedef long long ll;
ostream &debug = cout;

/* AOJ 2249 */

const int N = 10005;
const int M = 40005;
const int INF = 0x3f3f3f3f;

int n, m, ans, dis[N], vis[N];
int hd[N], to[M], nt[M], vl[M], ct[M], tot;

struct Node {
	int dis, wei, ver;
	friend bool operator <(Node a, Node b) {
		if (a.dis != b.dis)
			return a.dis > b.dis;
		return a.wei > b.wei;
	}
};

priority_queue<Node> pq;

inline void addEdge(int x, int y, int w, int c) {
	nt[tot] = hd[x], to[tot] = y, vl[tot] = w, ct[tot] = c, hd[x] = tot++;
}

signed main(void) {
	while (scanf("%d%d", &n, &m), n) {
		/* input & prepare */
		{
			memset(hd, -1, sizeof(hd)), tot = ans = 0;
			for (int i = 1, u, v, w, c; i <= m; i++)
				scanf("%d%d%d%d", &u, &v, &w, &c),
				addEdge(u, v, w, c), addEdge(v, u, w, c);
		}
		/* dijkstra */
		{
			pq.push(Node{0, 0, 1});
			memset(vis, 0, sizeof(vis));
			while (!pq.empty()) {
				Node top = pq.top(); pq.pop();
				if (vis[top.ver])continue;
				ans += top.wei, vis[top.ver] = 1;
				for (int i = hd[top.ver]; ~i; i = nt[i])
					pq.push(Node{ top.dis + vl[i], ct[i], to[i] });
			}
		}
		/* output */
		printf("%d\n", ans);
	}
}