]";


    auto G = new Tuple!(int, long)[][](N + N - 1);
    auto uf = new UnionFind(N);

    foreach (e; E) {
        int i = e[0] + N;
        int u = uf.find(e[1]);
        int v = uf.find(e[2]);
        long w = e[3];
        if (u == v) continue;
        G[i] ~= tuple(uf.par[u], w * -uf.table[v]);
        G[i] ~= tuple(uf.par[v], w * -uf.table[u]);
        uf.unite(u, v, i);
    }

    auto ans = new long[](N);

    void dfs(int n, long w) {
        if (n < N) {
            ans[n] += w;
            return;
        }
        foreach (to; G[n]) {
            dfs(to[0], w + to[1]);
        }
    }

    dfs(E.back[0] + N, 0);
    ans.each!writeln;
}

class UnionFind {
    int N;
    int[] table;
    int[] par;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        par = N.iota.array;
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y, int p) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
        par[x] = p;
    }
}
