#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 1;   const long long LOG = 20;   vector<pair<long long, long long> > edg[MAXN];   long long sz[MAXN];   long long link[MAXN];   long long ans[MAXN];   bool used[MAXN];   vector<pair<long long, long long> > ost[MAXN];   long long dp[MAXN][LOG];   long long mx[MAXN][LOG];   long long timein[MAXN];   long long timeout[MAXN];   long long timer = 0;   long long first[MAXN];   vector<long long> h;   long long pos = 0;   bool cmp(tuple<long long, long long, long long, long long> a,            tuple<long long, long long, long long, long long> b) {     return get<2>(a) < get<2>(b);   }   long long fin(long long u) {     if (u == link[u]) return u;     return link[u] = fin(link[u]);   }   bool same(long long u, long long v) { return fin(u) == fin(v); }   void unite(long long u, long long v) {     u = fin(u);     v = fin(v);     if (sz[u] > sz[v]) swap(u, v);     sz[v] += sz[u];     link[u] = link[v];   }   void dfs(long long v, long long pred, long long w, long long ha) {     timein[v] = timer++;     mx[v][0] = w;     dp[v][0] = pred;     first[v] = pos;     h.push_back(ha);     pos++;     for (long long i = 1; i < LOG; i++) {       dp[v][i] = dp[dp[v][i - 1]][i - 1];       mx[v][i] = max(mx[v][i - 1], mx[dp[v][i - 1]][i - 1]);     }     for (auto u : ost[v])       if (u.first != pred) dfs(u.first, v, u.second, ha + 1);     timeout[v] = timer++;   }   bool upper(long long u, long long v) {     return timein[u] <= timein[v] && timeout[u] >= timeout[v];   }   long long lca(long long u, long long v) {     if (upper(u, v)) return u;     if (upper(v, u)) return v;     for (long long i = LOG - 1; i >= 0; i--)       if (!upper(dp[u][i], v)) u = dp[u][i];     return dp[u][0];   }   long long vis(long long u) { return h[first[u]]; }   long long getmax(long long u, long long v) {     long long ans = -1;     if (vis(u) < vis(v)) swap(u, v);     for (long long i = LOG - 1; i >= 0; i--)       if (vis(dp[u][i]) >= vis(v)) {         ans = max(ans, mx[u][i]);         u = dp[u][i];       }     return ans;   }   signed main() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long ver, a, b, w, n, m, i, j, sum = 0, num, c, ves = -1;     cin >> n >> m;     vector<tuple<long long, long long, long long, long long> > reb(m);     for (i = 0; i < m; i++) {       cin >> a >> b >> w;       edg[a].push_back({b, w});       edg[b].push_back({a, w});       reb[i] = make_tuple(a, b, w, i);     }     sort(reb.begin(), reb.end(), cmp);     for (i = 1; i <= n; i++) {       link[i] = i;       sz[i] = 1;     }     vector<long long> made;     for (i = 0; i < m; i++) {       tie(a, b, w, num) = reb[i];       if (!same(a, b)) {         unite(a, b);         sum += w;         made.push_back(num);         used[num] = true;         ost[a].push_back({b, w});         ost[b].push_back({a, w});       }     }     for (auto c : made) {       ans[c] = sum;       used[c] = true;     }     for (i = 0; i < LOG; i++) dp[1][i] = 1;     dfs(1, 1, 0, 0);     for (i = 0; i < m; i++) {       tie(a, b, w, num) = reb[i];       if (used[num]) continue;       c = lca(a, b);       ves = max(getmax(a, c), getmax(b, c));       ans[num] = sum - ves + w;     }     for (i = 0; i < m; i++) cout << ans[i] <<   n ;   }