using System;
using System.Collections.Generic;
using System.Linq;
using Debug = System.Diagnostics.Debug;
//using System.Numerics;
//using static System.Math;
using Number = System.Int64;

using C = System.Double;
using V = System.Double;

namespace Program {
    public class Solver {
        //const long MOD = (long)1e9 + 7;
        public void Solve() {
            var n = ri;
            var m = ri;
            var f = new int[m];
            var t = new int[m];
            var w = new long[m];
            for (int i = 0; i < m; i++) {
                f[i] = ri - 1; t[i] = ri - 1; w[i] = ri;
            }
            var mst = Enumerate(m, x => false);
            var ans = 0L;
            var T = new HLTree(n + m);
            var s = new DisjointSet(n);
            foreach (var id in Enumerate(m, x => x).OrderBy(x => w[x])) {
                if (s.Unite(f[id], t[id])) {
                    ans += w[id];
                    mst[id] = true;
                    T.AddEdge(f[id], n + id);
                    T.AddEdge(n + id, t[id]);
                }
            }
            if (s.Size(0) != n) {
                for (int i = 0; i < m; i++)
                    Console.WriteLine(-1);
                return;
            }
            T.Build();
            foreach (var id in Enumerate(m, x => x).OrderBy(x => w[x])) {
                if (!mst[id])
                    T.Push(f[id], t[id], w[id]);
            }
            for (int i = 0; i < m; i++) {
                if (!mst[i]) Console.WriteLine(ans);
                else {
                    var val = ans - w[i] + T.Get(f[i], t[i]);
                    if (val >= 1L << 60) val = -1;
                    Console.WriteLine(val);
                }
            }
        }
        const long INF = 1L << 60;
        //int[] dx = { 1, 0, -1, 0 };
        //int[] dy = { 0, 1, 0, -1 };
        //*
        int ri { get { return sc.Integer(); } }
        long rl { get { return sc.Long(); } }
        double rd { get { return sc.Double(); } }
        string rs { get { return sc.Scan(); } }
        //*/

        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region main
static class Ex {
    static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
        return string.Join(st, ie.Select(x => x.ToString()).ToArray());
        //return string.Join(st, ie);
    }
    static public void Main() {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Program.Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO {
    using System.Globalization;
    using System.IO;
    using System.Text;
    public class Printer: StreamWriter {
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    }
    public class StreamScanner {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read() {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan() {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine() {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n' && b != 0; b = (char)read())
                if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
        public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
        public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}
#endregion
#region DisjointSet
public class DisjointSet {
    int[] par;
    byte[] rank;
    public DisjointSet(int n) {
        par = new int[n];
        for (int i = 0; i < n; i++)
            par[i] = -1;
        rank = new byte[n];
    }
    public int this[int id] {
        get {
            if ((par[id] < 0)) return id;
            return par[id] = this[par[id]];
        }
    }
    public bool Unite(int x, int y) {
        x = this[x]; y = this[y];
        if (x == y) return false;
        if (rank[x] < rank[y]) { var z = x; x = y; y = z; }
        par[x] += par[y];
        par[y] = x;
        if (rank[x] == rank[y])
            rank[x]++;
        return true;
    }
    public int Size(int x) { return -par[this[x]]; }
    public bool IsUnited(int x, int y) { return this[x] == this[y]; }

}
#endregion

public class HLTree {
    int n;
    List<int>[] G;
    int[] subtreeSize;
    int[] maxsize;
    int[] par;
    int[] d;

    Chain[] go;
    int[] pos;
    List<Chain> chains;
    public HLTree(int N) {
        n = N;
        G = new List<int>[n];
        chains = new List<Chain>();
        for (int i = 0; i < n; i++)
            G[i] = new List<int>();
        subtreeSize = new int[n];
        maxsize = new int[n];
        par = new int[n];
        d = new int[n];
        go = new Chain[n];
        pos = new int[n];
    }
    public void AddEdge(int u, int v) {
        G[u].Add(v); G[v].Add(u);
    }
    public void Build(int root = 0) {
        computeSubtreeSize(root);
        Decomposite(-1, root, 0);

    }
    void computeSubtreeSize(int r) {
        var stack = new Stack<int>();
        stack.Push(r);
        var iter = new int[n];
        par[r] = -1;
        //dfs
        while (stack.Count > 0) {
            var cur = stack.Peek();
            if (iter[cur] == G[cur].Count) {
                stack.Pop();
                subtreeSize[cur]++;
                if (par[cur] != -1) {
                    subtreeSize[par[cur]] += subtreeSize[cur];
                    maxsize[par[cur]] = Math.Max(maxsize[par[cur]], subtreeSize[cur]);
                }
                continue;
            }
            var next = G[cur][iter[cur]++];
            if (next == par[cur]) continue;
            par[next] = cur;
            d[next] = d[cur] + 1;
            stack.Push(next);
        }

    }
    void Decomposite(int from, int cur, int lv) {
        var chain = new Chain(from, lv);
        chains.Add(chain);
        chain.Add(cur);
        while (cur != from) {
            var next = cur;
            go[cur] = chain;
            pos[cur] = chain.Count;
            foreach (var to in G[cur]) {
                if (to == from) continue;
                if (maxsize[cur] == subtreeSize[to]) {
                    maxsize[cur] = -1;
                    next = to;
                    chain.Add(to);
                }
                else Decomposite(cur, to, lv + 1);
            }

            from = cur;
            cur = next;

        }
        chain.Init();

    }
    public int GetLCA(int u, int v) {
        while (go[u] != go[v]) {
            if (go[u].Level < go[v].Level) v = go[v].From;
            else u = go[u].From;
        }
        if (d[u] <= d[v]) return u;
        else return v;
    }
    public void Push(int u, int v, long w) {
        while (go[u] != go[v]) {
            if (go[u].Level < go[v].Level) {
                go[v].seg.Push(0, pos[v], w);
                v = go[v].From;
            }
            else {
                go[u].seg.Push(0, pos[u], w);
                u = go[u].From;
            }
        }
        if (d[u] <= d[v]) go[u].seg.Push(pos[u], pos[v], w);
        else go[u].seg.Push(pos[v], pos[u], w);
    }
    public long Get(int u, int v) {
        long ret = long.MaxValue;
        while (go[u] != go[v]) {
            if (go[u].Level < go[v].Level) {
                ret = Math.Min(ret, go[v].seg.Query(0, pos[v]));
                v = go[v].From;
            }
            else {
                ret = Math.Min(ret, go[u].seg.Query(0, pos[u]));
                u = go[u].From;
            }
        }
        if (d[u] <= d[v]) ret = Math.Min(ret, go[u].seg.Query(pos[u], pos[v]));
        else ret = Math.Min(ret, go[u].seg.Query(pos[v], pos[u]));
        return ret;
    }
}



public class Chain {
    const bool DEBUG = true;
    public int From { get; set; }
    public int Level { get; set; }
    public int Count { get; private set; }

    List<int> heavy;
    public SetMinTree seg;
    public Chain(int from, int lv) {
        From = from;
        Level = lv;
        heavy = new List<int>();
    }
    public void Add(int v) {
        if (DEBUG)
            heavy.Add(v);
        Count++;
    }
    public void Init() {
        seg = new SetMinTree(Count);
    }
}

#region Lazy Propagation
public interface ILazyData<T1, T2> {
    T1 Merge(T1 l, T1 r);
    T1 Identity { get; }
    T1 InitValue { get; }
    T1 Apply(int l, int r, T1 val, T2 x);
    T2 Push(T2 val, T2 x);
    T2 Zero { get; }
}
#endregion
#region LazyPropagation Segment Tree
public class LazyPropagationSegmentTree<T1, T2, U>
    where U : struct, ILazyData<T1, T2> {
    int sz;
    int n;
    T1[] data;
    T2[] lazy;
    bool[] flag;
    U op;
    public LazyPropagationSegmentTree(int size) {
        sz = size;
        n = 1;
        while (n < sz)
            n <<= 1;
        data = new T1[n * 2];
        lazy = new T2[n * 2];
        flag = new bool[n * 2];
        for (int i = 1; i < n * 2; i++) {
            data[i] = op.InitValue;
            lazy[i] = op.Zero;
        }
    }
    public LazyPropagationSegmentTree(T1[] a) {

        sz = a.Length;
        n = 1;
        while (n < sz)
            n <<= 1;
        data = new T1[n * 2];
        lazy = new T2[n * 2];
        flag = new bool[n * 2];
        for (int i = 0; i < n; i++) {
            if (i < sz)
                data[i + n] = a[i];
            else data[i + n] = op.InitValue;
            lazy[i + n] = op.Zero;
        }
        for (int i = n - 1; i >= 1; i--) {
            data[i] = op.Merge(data[i * 2], data[i * 2 + 1]);
            lazy[i] = op.Zero;

        }
    }
    private void lazyEval(int k, int a, int b) {
        if (!flag[k])
            return;
        push(a, (a + b) / 2, lazy[k], k * 2, a, (a + b) / 2);
        push((a + b) / 2, b, lazy[k], k * 2 + 1, (a + b) / 2, b);
        lazy[k] = op.Zero;
        flag[k] = false;
    }
    private void eval(int k) {
        data[k] = op.Merge(data[k * 2], data[k * 2 + 1]);
    }

    public void Push(int a, int b, T2 v) {
        push(a, b, v, 1, 0, n);
    }
    private void push(int a, int b, T2 x, int k, int l, int r) {
        if (r <= a || b <= l)
            return;
        else if (a <= l && r <= b) {
            flag[k] = true;
            lazy[k] = op.Push(lazy[k], x);
            data[k] = op.Apply(l, r, data[k], x);
        }
        else {
            lazyEval(k, l, r);
            push(a, b, x, k << 1, l, (l + r) >> 1);
            push(a, b, x, (k << 1) + 1, (l + r) >> 1, r);
            eval(k);
        }
    }
    public T1 Query(int a, int b) { return query(a, b, 1, 0, n); }
    private T1 query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)
            return op.Identity;
        if (a <= l && r <= b)
            return data[k];
        else {
            lazyEval(k, l, r);
            var vl = query(a, b, k << 1, l, (l + r) >> 1);
            var vr = query(a, b, (k << 1) + 1, (l + r) >> 1, r);
            eval(k);
            return op.Merge(vl, vr);
        }
    }
    public T1[] Items {
        get {
            var ret = new T1[sz];
            for (int i = 0; i < ret.Length; i++)
                ret[i] = Query(i, i + 1);
            return ret;
        }
    }
}
#endregion

#region Set Min Tree
public class SetMinTree: LazyPropagationSegmentTree<long, long, SetSum> {
    public SetMinTree(int size) : base(size) { }
}
public struct SetSum: ILazyData<long, long> {
    public long Identity { get { return 1L << 60; } }
    public long InitValue { get { return 1L << 60; } }
    public long Zero { get { return 1L << 60; } }
    public long Apply(int l, int r, long val, long x) { return Math.Min(val, x); }
    public long Merge(long l, long r) { return Math.Min(l, r); }
    public long Push(long val, long x) { return Math.Min(val, x); }
}
#endregion


Measured memory_bytes: 78928