#include <bits/stdc++.h>
using namespace std;
namespace IO {
char buf[1 << 21], *p1 = buf, *p2 = buf, buf1[1 << 21];
inline char gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <class I>
inline void read(I &x) {
  x = 0;
  I f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class I>
inline void write(I x) {
  if (x == 0) {
    putchar('0');
    return;
  }
  I tmp = x > 0 ? x : -x;
  if (x < 0) putchar('-');
  long long cnt = 0;
  while (tmp > 0) {
    buf1[cnt++] = tmp % 10 + '0';
    tmp /= 10;
  }
  while (cnt > 0) putchar(buf1[--cnt]);
}
}  // namespace IO
using namespace IO;
long long n, m;
struct Edge {
  long long start;
  long long end;
  long long val;
  long long nexty;
  long long ID;
  bool operator<(Edge p) const { return val < p.val; }
} edge[1000010], bian[1000010];
long long link[1000010], edge_cnt;
void add_edge(long long u, long long v, long long w, long long ID) {
  edge[++edge_cnt] = (Edge){u, v, w, link[u], ID};
  link[u] = edge_cnt;
}
long long head[1000010], bian_cnt;
void add_bian(long long u, long long v, long long w = 0) {
  bian[++bian_cnt] = (Edge){u, v, w, head[u], 0};
  head[u] = bian_cnt;
}
template <class I>
class U_Set {
 private:
  I f[1000010];

 public:
  void init(long long lim) {
    for (long long i = 0; i <= lim; i++) {
      this->f[i] = i;
    }
  }
  long long find(long long x) {
    if (x == f[x]) {
      return f[x];
    }
    return f[x] = find(f[x]);
  }
  void merge(long long x, long long y) { f[x] = y; }
};
U_Set<long long> u_set;
long long weight = 0;
void kruskal() {
  long long total = 0;
  std::sort(edge + 1, edge + edge_cnt + 1);
  u_set.init(n);
  for (long long i = 1; i <= edge_cnt; i++) {
    long long u = u_set.find(edge[i].start);
    long long v = u_set.find(edge[i].end);
    if (u == v) {
      continue;
    }
    add_bian(edge[i].start, edge[i].end, edge[i].val);
    add_bian(edge[i].end, edge[i].start, edge[i].val);
    weight += edge[i].val;
    u_set.merge(u, v);
    if (++total == n - 1) {
      break;
    }
  }
  return;
}
long long tot[1000010], top[1000010], depth[1000010];
long long son[1000010], fa[1000010], id[1000010];
long long a[1000010], b[1000010], dfs_cnt;
long long dfs1(long long now, long long f, long long dep) {
  depth[now] = dep;
  fa[now] = f;
  tot[now] = 1;
  long long maxson = -1;
  for (long long i = head[now]; i; i = bian[i].nexty) {
    if (bian[i].end == f) {
      continue;
    }
    tot[now] += dfs1(bian[i].end, now, dep + 1);
    b[bian[i].end] = bian[i].val;
    if (maxson < tot[bian[i].end]) {
      maxson = tot[bian[i].end];
      son[now] = bian[i].end;
    }
  }
  return tot[now];
}
void dfs2(long long now, long long topf) {
  top[now] = topf;
  id[now] = ++dfs_cnt;
  a[dfs_cnt] = b[now];
  if (!son[now]) {
    return;
  }
  dfs2(son[now], topf);
  for (long long i = head[now]; i; i = bian[i].nexty) {
    if (!id[bian[i].end]) {
      dfs2(bian[i].end, bian[i].end);
    }
  }
  return;
}
class Segment_Fold {
 private:
  struct Seg_Tree {
    long long l, r;
    long long val;
  } tree[1000010];

 public:
  void pushup(long long ID) {
    tree[ID].val = std::max(tree[ID << 1].val, tree[ID << 1 | 1].val);
  }
  void build(long long ID, long long l, long long r) {
    tree[ID].l = l, tree[ID].r = r;
    if (l == r) {
      tree[ID].val = a[l];
      return;
    }
    long long mid = (l + r) >> 1;
    build(ID << 1, l, mid);
    build(ID << 1 | 1, mid + 1, r);
    pushup(ID);
    return;
  }
  long long query(long long ID, long long l, long long r) {
    if (tree[ID].l >= l && tree[ID].r <= r) {
      return tree[ID].val;
    }
    long long ans = -0x3f3f3f3f3f3f;
    long long mid = (tree[ID].l + tree[ID].r) >> 1;
    if (l <= mid) {
      ans = std::max(ans, query(ID << 1, l, r));
    }
    if (r > mid) {
      ans = std::max(ans, query(ID << 1 | 1, l, r));
    }
    return ans;
  }
  long long request(long long x, long long y) {
    long long ans = -0x3f3f3f3f3f3f;
    while (top[x] != top[y]) {
      if (depth[top[x]] < depth[top[y]]) {
        std::swap(x, y);
      }
      ans = std::max(ans, query(1, id[top[x]], id[x]));
      x = fa[top[x]];
    }
    if (depth[x] > depth[y]) {
      std::swap(x, y);
    }
    ans = std::max(ans, query(1, id[x] + 1, id[y]));
    return ans;
  }
} se;
long long root = 1;
bool my_cmp(Edge a, Edge b) { return a.ID < b.ID; }
signed main() {
  read(n), read(m);
  for (long long i = 1, u, v, w; i <= m; i++) {
    read(u), read(v), read(w);
    add_edge(u, v, w, i);
    add_edge(v, u, w, i);
  }
  kruskal();
  dfs1(root, 0, 1);
  dfs2(root, root);
  se.build(1, 1, n);
  std::sort(edge + 1, edge + edge_cnt + 1, my_cmp);
  for (long long i = 1; i <= edge_cnt; i += 2) {
    long long u = edge[i].start;
    long long v = edge[i].end;
    write(weight - se.request(u, v) + edge[i].val), putchar('\n');
  }
  return 0;
}
