#include <bits/stdc++.h>   using namespace std;   struct three {     int f, s, w;   };   map<pair<int, int>, bool> mp;   int parent[200005], pat[200005];   three A[200005];   int time_in[200005], time_out[200005];   vector<vector<int> > dp(200005);   vector<vector<int> > dp_mx(200005);   vector<vector<pair<int, int> > > g;   vector<vector<pair<int, int> > > tree;   set<pair<int, pair<int, int> > > st;   set<pair<int, pair<int, int> > >::iterator st_it;   void make_set(int);   int find_set(int);   void union_sets(int, int);   bool subtree(int, int);   int lca(int, int);   void DFS(int, int, int);   int get_max(int, int);   int n, m;   int a, b;   int timer;   int lg;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     g.resize(n + 1);     tree.resize(n + 1);     for (int k = 1; k <= n; k++) make_set(k);     for (int k = 1; k <= m; k++) {       cin >> A[k].f >> A[k].s >> A[k].w;       g[A[k].f].push_back(make_pair(A[k].s, A[k].w));       g[A[k].s].push_back(make_pair(A[k].f, A[k].w));       st.insert(make_pair(A[k].w, make_pair(A[k].f, A[k].s)));     }     long long ans = 0;     while (!st.empty()) {       st_it = st.begin();       a = st_it->second.first;       b = st_it->second.second;       while (find_set(a) == find_set(b)) {         st.erase(st_it);         if (st.empty()) break;         st_it = st.begin();         a = st_it->second.first;         b = st_it->second.second;       }       if (st.empty()) break;       union_sets(a, b);       mp[{a, b}] = 1;       mp[{b, a}] = 1;       tree[a].push_back(make_pair(b, st_it->first));       tree[b].push_back(make_pair(a, st_it->first));       ans += st_it->first;       st.erase(st_it);     }     lg = log2(n + 1);     for (int k = 0; k <= n; k++) {       dp[k].resize(lg + 1);       dp_mx[k].resize(lg + 1);     }     DFS(1, 0, 0);     for (int k = 1; k <= m; k++) {       int pq = lca(A[k].f, A[k].s);       int q = max(get_max(A[k].f, pq), get_max(A[k].s, pq));       long long cnt = ans - q + A[k].w;       cout << cnt <<   n ;     }     return 0;   }   void make_set(int v) { parent[v] = v; }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) parent[b] = a;   }   void DFS(int v, int p, int d) {     pat[v] = p;     dp[v][0] = p;     dp_mx[v][0] = d;     for (int k = 1; k <= lg; k++) {       dp[v][k] = dp[dp[v][k - 1]][k - 1];       if (dp[v][k] != 0)         dp_mx[v][k] = max(dp_mx[v][k - 1], dp_mx[dp[v][k - 1]][k - 1]);     }     time_in[v] = timer++;     for (int k = 0; k < tree[v].size(); k++) {       int to = tree[v][k].first;       if (to == p) continue;       DFS(to, v, tree[v][k].second);     }     time_out[v] = timer++;   }   bool subtree(int a, int b) {     if (time_in[a] <= time_in[b] && time_out[b] <= time_out[a]) return 1;     return 0;   }   int lca(int a, int b) {     if (subtree(a, b)) return a;     if (subtree(b, a)) return b;     for (int k = lg; k >= 0; k--) {       if (dp[a][k] == 0) continue;       if (subtree(dp[a][k], b)) continue;       a = dp[a][k];     }     return pat[a];   }   int get_max(int a, int lca) {     int counter = -1;     for (int k = lg; k >= 0; k--) {       if (dp[a][k] == 0) continue;       if (subtree(dp[a][k], lca) && dp[a][k] != lca) continue;       counter = max(counter, dp_mx[a][k]);       a = dp[a][k];     }     return counter;   }   