#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct edge {
  int t, d, c;
  edge() {}
  edge(int t, int d, int c) : t(t), d(d), c(c) {}
};

const int INF = 1 << 30;
int N, M;
int u[200010], v[200010], d[200010], c[200010];
vector<edge> g[100010];
int dis[100010][1010];

void init() {
  for (int i = 0; i < N; i++) {
    g[i].clear();
    for (int j = 0; j < 1010; j++) {
      dis[i][j] = INF;
    }
  }
}

void dijkstra() {
  dis[0][0] = 0;
  using P = tuple<int, int, int>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.emplace(0, 0, 0);
  while (!que.empty()) {
    int dd, cur, pre;
    tie(dd, cur, pre) = que.top();
    que.pop();
    if (dd < dis[cur][pre]) continue;
    for (edge e : g[cur]) {
      if (dis[e.t][e.c] > dis[cur][pre] + e.d) {
        dis[e.t][e.c] = dis[cur][pre] + e.d;
        que.emplace(dis[e.t][e.c], e.t, e.c);
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> N >> M, N) {
    init();
    for (int i = 0; i < M; i++) {
      cin >> u[i] >> v[i] >> d[i] >> c[i];
      u[i]--; v[i]--;
      g[u[i]].emplace_back(v[i], d[i], c[i]);
      g[v[i]].emplace_back(u[i], d[i], c[i]);
    }
    dijkstra();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      int mind = INF, add = -1;
      for (int j = 0; j < 1010; j++) {
        if (dis[i][j] < mind) {
          mind = dis[i][j];
          add = j;
        }
      }
      ans += add;
    }
    cout << ans << endl;
  }

  return 0;
}
