#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;

class Edge{
    public:
        int to, dis, cost;
        Edge(int to, int dis, int cost) : to(to) ,dis(dis), cost(cost) {}
};

class Node{
    public:
        int dis;
        int cost;
        bool isUsed;
        Node(){
            this->dis = INF;
            this->cost = INF;
            this->isUsed = 0;
        }
};

typedef vector<vector<Edge>> AdjList;

void dijkstra(AdjList g, vector<Node> &node, int start, int n){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;

    q.push(make_pair(0, start));
    node[start].dis = 0;

    pair<int, int> u;
    while(not q.empty()){
        u = q.top(); q.pop();
        int current = u.second;
        node[current].isUsed = 1;

        rep(i,g[current].size()){
            int next = g[current][i].to;
            if(node[next].isUsed == 0){
                if(node[next].dis > node[current].dis + g[current][i].dis){
                    node[next].dis = node[current].dis + g[current][i].dis;
                    q.push(make_pair(node[next].dis, next));

                }
            }
        }
    }
}

int solve(AdjList g, vector<Node> dis, int n){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    vector<Node> node(n);

    q.push(make_pair(0, 0)); //?????????????????¨?????????
    node[0].dis = 0;
    node[0].cost = 0;
    /*
    rep(i,g[0].size()){
        node[i].dis = g[0][i].dis;
        node[i].cost = g[0][i].cost;
        q.push(make_pair(make_pair(g[0][i].cost, g[0][i].dis), g[0][i].to));
    }
    */

    pair<int, int> u;
    while(not q.empty()){
        u = q.top(); q.pop();
        /*
        show(u.first);
        show(u.second);
        */
        int current = u.second;
        node[current].isUsed = 0;

        rep(i,g[current].size()){
            int next = g[current][i].to;
            if(node[next].isUsed == 0){
                if(node[next].cost <= g[current][i].cost) continue;
                if(dis[next].dis == node[current].dis + g[current][i].dis){
                    node[next].dis = node[current].dis + g[current][i].dis;
                    node[next].cost = g[current][i].cost;
                    q.push(make_pair(g[current][i].cost, next));
                }

            }
        }
    }
    int sum = 0;
    rep(i,n){
        //show(node[i].cost)
        sum+=node[i].cost;
    }
    return sum;
}


int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        AdjList g(n);
        rep(i,m){
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            a--; b--;
            g[a].emplace_back(Edge(b, c, d));
            g[b].emplace_back(Edge(a, c, d));
        }
        vector<Node> node(n);
        dijkstra(g, node, 0, n); //node???????????????????????????????????\???
        //rep(i,n){ show(node[i].dis); }
        cout << solve(g, node, n) << endl;
    }
}

Measured memory_bytes: 4652