#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

struct edge{
	int id;
	int u,v,w;
};

const int N=2e5+10;
int link[N],sz[N];
int msp[N];
map<ii,int> ew;
vi adj[N];
int dep[N];
int par[N];
int d=0;
const int lim=log2(N)+5;
int lift[N][lim],mx[N][lim];

int find(int x) {
    while (x != link[x]) x = link[x];
    return x;
}
bool same(int a, int b) {
    return find(a) == find(b);
}
void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if(a!=b){
        if (sz[a] < sz[b]) swap(a,b);
        sz[a] += sz[b];
        link[b] = a;
    }
}

bool cmp(edge a,edge b){
	if(a.w==b.w){
		return a.id < b.id;
	}else{
		return a.w < b.w;
	}
}

bool cmp2(edge a, edge b){
	return a.id < b.id;
}

void dfs(int s, int e) {
	d++;
	for (auto u : adj[s]) {
		if (u != e) dfs(u, s);
	}
	par[s]=e;
	dep[s]=d;
	d--;
}

int go(int x,int k){
	//dg3(x,k,lift[5][0]);
	for(int i=0;i<23;i++){
		if(k&(1<<i)){
			x=lift[x][i];
		}
	}
	return x;
}

int go2(int x,int k){
	int ans=0;
	for(int i=0;i<23;i++){
		if(k&(1<<i)){
			ans=max(ans,mx[x][i]);
			x=lift[x][i];
		}
	}
	return ans;
}

bool check(int mid,int x,int y){
	x=go(x,mid);
	y=go(y,mid);
	if(x==y){
		return true;
	}else{
		return false;
	}
}

int lca(int x,int y){
	if(dep[y]>dep[x])swap(x,y);
	//dg4(x,dep[x],y,dep[y]);
	if(dep[x]>dep[y])x=go(x,abs(dep[x]-dep[y]));
	//dg2(x,y);
	int l=0,r=N,mid,ans;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid,x,y)){
			ans=mid;
			r=mid-1;
		}else{
			l=mid+1;
		}
	}
	if(ans>0)x=go(x,ans);
	return x;
}

int32_t main(){
    boost;
    for(int i=0;i<N;i++){
    	link[i]=i;
    	sz[i]=1;
    }
    int n,m;
    cin>>n>>m;
    edge ed[m];
    rep(i,0,m){
    	ed[i].id=i;
    	cin>>ed[i].u>>ed[i].v>>ed[i].w;
    	ew[mp(ed[i].u,ed[i].v)]=ed[i].w;
    	ew[mp(ed[i].v,ed[i].u)]=ed[i].w;
    }
    sort(ed,ed+m,cmp);
    int res=0;
    for(int i=0;i<m;i++){
    	if(!same(ed[i].u,ed[i].v)){
    		msp[ed[i].id]++;
    		unite(ed[i].u,ed[i].v);
    		res+=ed[i].w;
    		adj[ed[i].u].pb(ed[i].v);
    		adj[ed[i].v].pb(ed[i].u);
    	}
    }
    dfs(1,0);
    for(int i=n;i>0;i--){
    	lift[i][0]=par[i];
    	mx[i][0]=ew[mp(i,par[i])];
    }
    for(int x=n;x>0;x--){
    	for(int j=1;j<lim;j++){
    		lift[x][j]=lift[lift[x][j-1]][j-1];
    		mx[x][j]=max(mx[x][j-1],mx[lift[x][j-1]][j-1]);
    	}
    }
    sort(ed,ed+m,cmp2);
    for(int i=0;i<m;i++){
    	if(msp[ed[i].id]){
    		//cout<<"In msp:";
    		cout<<res<<endl;
    	}else{
    		//cout<<"Not in msp:";
    		int lc=lca(ed[i].u,ed[i].v);
    		if(lc<=0){
    			cout<<lc;
    			return 0;
    		}
    		int x1=dep[ed[i].u]-dep[lc];
    		int x2=dep[ed[i].v]-dep[lc];
    		int res1=go2(ed[i].u,x1);
    		int res2=go2(ed[i].v,x2);
    		int res3=max(res1,res2);
    		cout<<res+ed[i].w-res3<<endl;
    	}
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<ll> level,par;
unordered_map<ll,unordered_map<ll,ll>> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return edgewt[min(x,y)][max(x,y)];
}

ll kruskal(ll n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    ll ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[min(i[0],i[1])][max(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgeind(src,p);
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        ll next=binlift[src][i-1];
        if(next!=-1){
            binlift[src][i]=binlift[next][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[next][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

// void lcainit(int n){
//     for(int i=0;i<n;++i){
//         if(par[i]!=-1){
//             binlift[i][0]=par[i];
//             maxedge[i][0]=edgewt[edgeind(i,par[i])];
//         }
//     }
//     for(int j=1;j<21;++j)
//         for(int i=0;i<n;++i){
//             ll jump=binlift[i][j-1];
//             binlift[i][j]=binlift[jump][j-1];
//             maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
//         }
// }

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
            if(x==y) return ret;
        }
    }

    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ll n,m,i;
    cin>>n>>m;
    ++n;
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u,v,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    ll sum=kruskal(n);
    cout<<"Sum=> "<<sum<<endl;
    // for(auto i:graph){
    //     for(auto j:i) cout<<j<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    // for(int i=0;i<n;++i){
	// 	cout<<i<<"  ==>> ";
	// 	for(int j=0;j<Log;++j)
	// 		cout<<maxedge[i][j]<<" ";
	// 		cout<<endl;
	// }
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(auto i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<ll> level,par;
unordered_map<ll,unordered_map<ll,ll>> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return edgewt[min(x,y)][max(x,y)];
}

ll kruskal(ll n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    ll ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[min(i[0],i[1])][max(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgeind(src,p);
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        ll next=binlift[src][i-1];
        if(next!=-1){
            binlift[src][i]=binlift[next][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[next][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

// void lcainit(int n){
//     for(int i=0;i<n;++i){
//         if(par[i]!=-1){
//             binlift[i][0]=par[i];
//             maxedge[i][0]=edgewt[edgeind(i,par[i])];
//         }
//     }
//     for(int j=1;j<21;++j)
//         for(int i=0;i<n;++i){
//             ll jump=binlift[i][j-1];
//             binlift[i][j]=binlift[jump][j-1];
//             maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
//         }
// }

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
            if(x==y) return ret;
        }
    }

    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,i;
    cin>>n>>m;
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u-1,v-1,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    ll sum=kruskal(n);
    // cout<<"Sum=> "<<sum<<endl;
    // for(auto i:graph){
    //     for(auto j:i) cout<<j<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    // for(int i=0;i<n;++i){
	// 	cout<<i<<"  ==>> ";
	// 	for(int j=0;j<Log;++j)
	// 		cout<<maxedge[i][j]<<" ";
	// 		cout<<endl;
	// }
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(ll i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<ll> level,par;
unordered_map<ll,unordered_map<ll,ll>> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return edgewt[min(x,y)][max(x,y)];
}

ll kruskal(ll n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    ll ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[min(i[0],i[1])][max(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgeind(src,p);
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        ll next=binlift[src][i-1];
        if(next!=-1){
            binlift[src][i]=binlift[next][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[next][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

// void lcainit(int n){
//     for(int i=0;i<n;++i){
//         if(par[i]!=-1){
//             binlift[i][0]=par[i];
//             maxedge[i][0]=edgewt[edgeind(i,par[i])];
//         }
//     }
//     for(int j=1;j<21;++j)
//         for(int i=0;i<n;++i){
//             ll jump=binlift[i][j-1];
//             binlift[i][j]=binlift[jump][j-1];
//             maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
//         }
// }

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
            if(x==y) return ret;
        }
    }

    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,i;
    cin>>n>>m;
    ++n;
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u,v,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    ll sum=kruskal(n);
    // cout<<"Sum=> "<<sum<<endl;
    // for(auto i:graph){
    //     for(auto j:i) cout<<j<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    // for(int i=0;i<n;++i){
	// 	cout<<i<<"  ==>> ";
	// 	for(int j=0;j<Log;++j)
	// 		cout<<maxedge[i][j]<<" ";
	// 		cout<<endl;
	// }
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(auto i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<int> level,par;
unordered_map<ll,ll> edgewt;

ll edgeind(ll x,ll y){
    return min(x,y)*1e6+max(x,y);
}

ll kruskal(int n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    int ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[x].push_back(y);
        graph[y].push_back(x);
        if(x<y) swap(x,y);
        edgewt[edgeind(x,y)]=i[2];
        ret+=i[2];
    }
    return ret;
}

void bfs(int src){
    queue<ll> qu;
    qu.push(src);
    level[src]=1;
    while(!qu.empty()){
        int v=qu.front();
        for(auto i:graph[v]){
            if(!level[i]){
                level[i]=level[v]+1;
                par[i]=src;
                qu.push(i);
            }
        }
        qu.pop();
    }
}

void lcainit(int n){
    for(int i=0;i<n;++i){
        if(par[i]!=-1){
            binlift[i][0]=par[i];
            maxedge[i][0]=edgewt[edgeind(i,par[i])];
        }
    }
    for(int j=1;(1<<j)<n;++j)
        for(int i=0;i<n;++i){
            if(par[binlift[i][j-1]]!=-1){
                ll jump=par[binlift[i][j-1]];
                binlift[i][j]=jump;
                maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
            }
        }
}

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y];
    // cout<<"diff--> "<<diff<<endl;
    for(int j=0;j<21;++j){
        if(j&diff){
            ret=max(ret,maxedge[x][j]);
            x=binlift[x][j];
            if(x==y) return ret;
        }
    }
    for(int i=20;i>=0;--i){
        if(binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,edgewt[edgeind(x,par[x])],edgewt[edgeind(y,par[y])]});

}

int main(){
    ll n,m,i;
    cin>>n>>m;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u-1,v-1,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    int sum=kruskal(n);
    binlift.resize(n,vector<ll>(21));
    maxedge.resize(n,vector<ll>(21));
    par.resize(n,-1);
    level.resize(n);
    bfs(0);
    lcainit(n);
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(auto i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<ll> level,par;
unordered_map<ll,unordered_map<ll,ll>> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return edgewt[min(x,y)][max(x,y)];
}

ll kruskal(ll n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    ll ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[min(i[0],i[1])][max(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgeind(src,p);
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        ll next=binlift[src][i-1];
        if(next!=-1){
            binlift[src][i]=binlift[next][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[next][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

// void lcainit(int n){
//     for(int i=0;i<n;++i){
//         if(par[i]!=-1){
//             binlift[i][0]=par[i];
//             maxedge[i][0]=edgewt[edgeind(i,par[i])];
//         }
//     }
//     for(int j=1;j<21;++j)
//         for(int i=0;i<n;++i){
//             ll jump=binlift[i][j-1];
//             binlift[i][j]=binlift[jump][j-1];
//             maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
//         }
// }

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
            if(x==y) return ret;
        }
    }

    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,i;
    cin>>n>>m;
    if(!m) {
        cout<<endl;
        return 0;
    }
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u-1,v-1,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    ll sum=kruskal(n);
    // cout<<"Sum=> "<<sum<<endl;
    // for(auto i:graph){
    //     for(auto j:i) cout<<j<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    // for(int i=0;i<n;++i){
	// 	cout<<i<<"  ==>> ";
	// 	for(int j=0;j<Log;++j)
	// 		cout<<maxedge[i][j]<<" ";
	// 		cout<<endl;
	// }
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(ll i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<int> level,par;
unordered_map<ll,ll> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return min(x,y)*1e6+max(x,y);
}

ll kruskal(int n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    int ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[edgeind(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgewt[edgeind(src,p)];
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        if(binlift[src][i-1]!=-1){
            binlift[src][i]=binlift[binlift[src][i-1]][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[binlift[src][i-1]][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
        }
    }
    if(x==y) return ret;
    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ll n,m,i;
    cin>>n>>m;
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u-1,v-1,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    int sum=kruskal(n);
    cout<<"Sum=> "<<sum<<endl;
    for(auto i:graph){
        for(auto j:i) cout<<j<<" ";
        cout<<endl;
    }
    cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    for(int i=0;i<n;++i){
		cout<<i<<"  ==>> ";
		for(int j=0;j<Log;++j)
			cout<<maxedge[i][j]<<" ";
			cout<<endl;
	}
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(auto i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<int> level,par;
unordered_map<ll,ll> edgewt;

ll edgeind(ll x,ll y){
    return min(x,y)*1e6+max(x,y);
}

ll kruskal(int n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    int ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[x].push_back(y);
        graph[y].push_back(x);
        if(x<y) swap(x,y);
        edgewt[edgeind(x,y)]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(int src){
    for(auto i:graph[src]){
        if(!level[i]){
            level[i]=level[src]+1;
            par[i]=src;
            dfs(i);
        }
    }
}

void lcainit(int n){
    for(int i=0;i<n;++i){
        if(par[i]!=-1){
            binlift[i][0]=par[i];
            maxedge[i][0]=edgewt[edgeind(i,par[i])];
        }
    }
    for(int j=1;(1<<j)<n;++j)
        for(int i=0;i<n;++i){
            if(par[binlift[i][j-1]]!=-1){
                ll jump=par[binlift[i][j-1]];
                binlift[i][j]=jump;
                maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
            }
        }
}

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y];
    for(int j=0;j<21;++j){
        if(j&diff){
            ret=max(ret,maxedge[x][j]);
            x=binlift[x][j];
            if(x==y) return ret;
        }
    }
    for(int i=20;i>=0;--i){
        if(binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,edgewt[edgeind(x,par[x])],edgewt[edgeind(y,par[y])]});

}

int main(){
    ll n,m,i;
    cin>>n>>m;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u-1,v-1,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    int sum=kruskal(n);
    binlift.resize(n,vector<ll>(21));
    maxedge.resize(n,vector<ll>(21));
    par.resize(n,-1);
    level.resize(n);
    // level[0]=1;
    dfs(0);
    lcainit(n);
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(auto i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<ll> level,par;
unordered_map<ll,unordered_map<ll,ll>> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return edgewt[min(x,y)][max(x,y)];
}

ll kruskal(ll n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    ll ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[min(i[0],i[1])][max(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgeind(src,p);
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        ll next=binlift[src][i-1];
        if(next!=-1){
            binlift[src][i]=binlift[next][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[next][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

// void lcainit(int n){
//     for(int i=0;i<n;++i){
//         if(par[i]!=-1){
//             binlift[i][0]=par[i];
//             maxedge[i][0]=edgewt[edgeind(i,par[i])];
//         }
//     }
//     for(int j=1;j<21;++j)
//         for(int i=0;i<n;++i){
//             ll jump=binlift[i][j-1];
//             binlift[i][j]=binlift[jump][j-1];
//             maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
//         }
// }

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
            if(x==y) return ret;
        }
    }

    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ll n,m,i;
    cin>>n>>m;
    ++n;
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u,v,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    ll sum=kruskal(n);
    // cout<<"Sum=> "<<sum<<endl;
    // for(auto i:graph){
    //     for(auto j:i) cout<<j<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    // for(int i=0;i<n;++i){
	// 	cout<<i<<"  ==>> ";
	// 	for(int j=0;j<Log;++j)
	// 		cout<<maxedge[i][j]<<" ";
	// 		cout<<endl;
	// }
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(auto i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<ll> level,par;
unordered_map<ll,unordered_map<ll,ll>> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return edgewt[min(x,y)][max(x,y)];
}

ll kruskal(ll n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    ll ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[min(i[0],i[1])][max(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgeind(src,p);
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        ll next=binlift[src][i-1];
        if(next!=-1){
            binlift[src][i]=binlift[next][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[next][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

// void lcainit(int n){
//     for(int i=0;i<n;++i){
//         if(par[i]!=-1){
//             binlift[i][0]=par[i];
//             maxedge[i][0]=edgewt[edgeind(i,par[i])];
//         }
//     }
//     for(int j=1;j<21;++j)
//         for(int i=0;i<n;++i){
//             ll jump=binlift[i][j-1];
//             binlift[i][j]=binlift[jump][j-1];
//             maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
//         }
// }

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
            if(x==y) return ret;
        }
    }

    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,i;
    cin>>n>>m;
    if(!m) {
        cout<<0<<endl;
        return 0;
    }
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u-1,v-1,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    ll sum=kruskal(n);
    // cout<<"Sum=> "<<sum<<endl;
    // for(auto i:graph){
    //     for(auto j:i) cout<<j<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    // for(int i=0;i<n;++i){
	// 	cout<<i<<"  ==>> ";
	// 	for(int j=0;j<Log;++j)
	// 		cout<<maxedge[i][j]<<" ";
	// 		cout<<endl;
	// }
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(ll i:ans) cout<<i<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> edges,graph,binlift,maxedge;
vector<int> level,par;
unordered_map<ll,ll> edgewt;
ll Log;
ll edgeind(ll x,ll y){
    return min(x,y)*1e6+max(x,y);
}

ll kruskal(int n){
    vector<ll> dsu(n,-1);
    graph.resize(n);
    function<ll(ll)> find=[&](ll x){
        if(dsu[x]<0) return x;
        return dsu[x]=find(dsu[x]);
    };
    function<void(ll,ll)> uniond = [&](ll x,ll y){
        if(x==y) return ;
        dsu[x]+=dsu[y];
        dsu[y]=x;
    };
    int ret=0;
    for(auto i:edges){
        ll x=find(i[0]),y=find(i[1]);
        if(x==y) continue;
        uniond(x,y);
        graph[i[0]].push_back(i[1]);
        graph[i[1]].push_back(i[0]);
        edgewt[edgeind(i[0],i[1])]=i[2];
        ret+=i[2];
    }
    return ret;
}

void dfs(ll src,ll p){
    if(p!=-1) level[src]=level[p]+1,maxedge[src][0]=edgewt[edgeind(src,p)];
    binlift[src][0]=p;
    for(int i=1;i<Log;++i){
        if(binlift[src][i-1]!=-1){
            binlift[src][i]=binlift[binlift[src][i-1]][i-1];
            maxedge[src][i]=max(maxedge[src][i-1],maxedge[binlift[src][i-1]][i-1]);
        }
    }
    for(auto i:graph[src])
        if(i!=p) dfs(i,src);
}

// void lcainit(int n){
//     for(int i=0;i<n;++i){
//         if(par[i]!=-1){
//             binlift[i][0]=par[i];
//             maxedge[i][0]=edgewt[edgeind(i,par[i])];
//         }
//     }
//     for(int j=1;j<21;++j)
//         for(int i=0;i<n;++i){
//             ll jump=binlift[i][j-1];
//             binlift[i][j]=binlift[jump][j-1];
//             maxedge[i][j]=max(maxedge[i][j-1],maxedge[jump][j-1]);
//         }
// }

ll querylca(ll x,ll y){
    if(level[x]<level[y]) swap(x,y);
    ll ret=0,diff=level[x]-level[y],i;
    for(i=Log;i>=0;--i){
        if((1<<i)&diff){
            ret=max(ret,maxedge[x][i]);
            x=binlift[x][i];
            if(x==y) return ret;
        }
    }

    for(i=Log-1;i>=0;--i){
        if(binlift[x][i]!=-1 && binlift[x][i]!=binlift[y][i]){
            ret=max({ret,maxedge[x][i],maxedge[y][i]});
            x=binlift[x][i];
            y=binlift[y][i];
        }
    }
    return max({ret,maxedge[x][0],maxedge[y][0]});
}

int main(){
    ll n,m,i;
    cin>>n>>m;
    ++n;
    Log=ceil(log2(n))+1;
    for(i=0;i<m;++i){
        ll u,v,w; cin>>u>>v>>w;
        edges.push_back({u,v,w,i});
    }
    auto comp=[](vector<ll> a,vector<ll> b){
        return a[2]<b[2];
    };
    sort(edges.begin(),edges.end(),comp);
    int sum=kruskal(n);
    // cout<<"Sum=> "<<sum<<endl;
    // for(auto i:graph){
    //     for(auto j:i) cout<<j<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    binlift.resize(n,vector<ll>(Log+1));
    maxedge.resize(n,vector<ll>(Log+1));
    par.resize(n,-1);
    level.resize(n);
    dfs(1,-1);
    // lcainit(n);
    // for(int i=0;i<n;++i){
	// 	cout<<i<<"  ==>> ";
	// 	for(int j=0;j<Log;++j)
	// 		cout<<maxedge[i][j]<<" ";
	// 		cout<<endl;
	// }
    vector<ll> ans(m);
    for(auto i:edges){
        ll lca=querylca(i[0],i[1]);
        ans[i[3]]=sum+i[2]-lca;
    }
    for(auto i:ans) cout<<i<<endl;
    return 0;
}


//B - Minimum spanning tree for each edge
//Assunto: LCA/ Krustal/ Union Find;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 200050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

vector<tuple<int, int, int>> edges, unorderedEdges;
vector<ii> grafo[MAX], pai(MAX);
vector<int> paiUF(MAX), peso(MAX, 1), depth(MAX), vis(MAX, 0);

int find(int x) {
    while(x != paiUF[x]) x = paiUF[x];
    return x;
}

int join(int a, int b) {
    a = find(a);
    b = find(b);
    if(peso[a] < peso[b]) swap(a, b);
    peso[a] += peso[b];
    paiUF[b] = a;
}

ll krustal() {
    ll ans = 0;
    sort(all(edges));
    loop(i, 0, edges.size()) {
        int peso, u, v;
        tie(peso, u, v) = edges[i];
        if(find(u) != find(v)) {
            join(u, v);
            ans += peso;
            grafo[u].pb({v, peso});
            grafo[v].pb({u, peso});
        }
    }
    return ans;
}

void dfs(int no) {
    vis[no] = 1;
    for(auto p : grafo[no]) {
        int viz = p.fi;
        if(vis[viz] != 1) {
            pai[viz] = {no, p.se};
            depth[viz] = depth[no] + 1;
            dfs(viz);
        }
    }
}

int lca(int u, int v) {
    int maxi = 0;
    while(depth[u] > depth[v]) {
        maxi = max(maxi, pai[u].se);
        u = pai[u].fi;
    }
    while(depth[v] > depth[u]) {
        maxi = max(maxi, pai[v].se);
        v = pai[v].fi;
    }
    while(u != v) {
        maxi = max(maxi, pai[u].se);
        u = pai[u].fi;
        maxi = max(maxi, pai[v].se);
        v = pai[v].fi;
    }
    return maxi;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    int n, m, u, v, w;
    cin >> n >> m;
    loop(i, 0, n+1) paiUF[i] = i;
    loop(i, 0, m) {
        cin >> u >> v >> w;
        edges.pb({w, u, v});
        unorderedEdges.pb({w, u, v});
    }
    ll ans = krustal();
    depth[1] = 0;
    dfs(1);
    loop(i, 0, m) {
        tie(w, u, v) = unorderedEdges[i];
        int la = lca(u, v);
        cout << ans - lca(u, v) + w << '\n';
    }
}


//B - Minimum spanning tree for each edge
//Assunto: LCA/ Krustal/ Union Find;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 200050
#define MOD 1000000007
#define LOG 25
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

vector<tuple<int, int, int>> edges, unorderedEdges;
vector<ii> grafo[MAX];
vector<int> paiUF(MAX), peso(MAX, 1), depth(MAX, -1);
int parent[LOG][MAX];
ll maxE[LOG][MAX];
map<ii, bool> used;

int find(int x) {
    while(x != paiUF[x]) x = paiUF[x];
    return x;
}

void join(int a, int b) {
    a = find(a);
    b = find(b);
    if(peso[a] < peso[b]) swap(a, b);
    peso[a] += peso[b];
    paiUF[b] = a;
}

ll krustal() {
    ll ans = 0;
    sort(all(edges));
    loop(i, 0, edges.size()) {
        int peso, u, v;
        tie(peso, u, v) = edges[i];
        if(find(u) != find(v)) {
            join(u, v);
            ans += peso;
            grafo[u].pb({v, peso});
            grafo[v].pb({u, peso});
            used[{min(u, v), max(u,v)}] = true;
        }
    }
    return ans;
}

void dfs(int no) {
    for(auto p : grafo[no]) {
        int viz = p.fi;
        if(depth[viz] == -1) {
            depth[viz] = depth[no] + 1;
            parent[0][viz] = no;
            maxE[0][viz] = p.se;
            dfs(viz);
        }
    }
}

void build(int node) {
    depth[node] = 0;
    dfs(node);
    loop(i, 1, LOG) {
        loop(j, 0, MAX) {
            parent[i][j] = parent[i-1][parent[i-1][j]];
            maxE[i][j] = max(maxE[i-1][j], maxE[i-1][parent[i-1][j]]);
        }
    }
}

ll lca(int u, int v) {
    ll maxi = 0;
    if(depth[v] > depth[u]) swap(u, v);
    loopBack(i, LOG - 1, 0)
        if(depth[u] - (1 << i) >= depth[v]) {
            maxi = max(maxi, maxE[i][u]);
            u = parent[i][u];
        }
    if(u == v) return maxi;
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    loopBack(i, LOG-1, 0) {
        if(parent[i][u] != parent[i][v]) {
            maxi = max(maxi, maxE[i][u]);
            u = parent[i][u];
            maxi = max(maxi, maxE[i][v]);
            v = parent[i][v];
        }
    }
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    return maxi;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    int n, m, u, v, w;
    cin >> n >> m;
    loop(i, 0, n+1) paiUF[i] = i;
    loop(i, 0, m) {
        cin >> u >> v >> w;
        u--; v--;
        edges.pb({w, u, v});
        unorderedEdges.pb({w, u, v});
    }
    ll ans = krustal();
    build(0);
    loop(i, 0, m) {
        tie(w, u, v) = unorderedEdges[i];
        ll resp;
        if(used[{min(u, v), max(u, v)}]) resp = ans;
        else {
            ll la = lca(u, v);
            resp = ans - la + w;
        }
        cout << resp << '\n';
    }
}


//B - Minimum spanning tree for each edge
//Assunto: LCA/ Krustal/ Union Find;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 200050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

vector<tuple<int, int, int>> edges, unorderedEdges;
vector<ii> grafo[MAX], pai(MAX);
vector<int> paiUF(MAX), peso(MAX, 1), depth(MAX), vis(MAX, 0);

int find(int x) {
    while(x != paiUF[x]) x = paiUF[x];
    return x;
}

int join(int a, int b) {
    a = find(a);
    b = find(b);
    if(peso[a] < peso[b]) swap(a, b);
    peso[a] += peso[b];
    paiUF[b] = a;
}

int krustal() {
    int ans = 0;
    sort(all(edges));
    loop(i, 0, edges.size()) {
        int peso, u, v;
        tie(peso, u, v) = edges[i];
        if(find(u) != find(v)) {
            join(u, v);
            ans += peso;
            grafo[u].pb({v, peso});
            grafo[v].pb({u, peso});
        }
    }
    return ans;
}

void dfs(int no) {
    vis[no] = 1;
    for(auto p : grafo[no]) {
        int viz = p.fi;
        if(vis[viz] != 1) {
            pai[viz] = {no, p.se};
            depth[viz] = depth[no] + 1;
            dfs(viz);
        }
    }
}

int lca(int u, int v) {
    int maxi = 0;
    while(depth[u] > depth[v]) {
        maxi = max(maxi, pai[u].se);
        u = pai[u].fi;
    }
    while(depth[v] > depth[u]) {
        maxi = max(maxi, pai[v].se);
        v = pai[v].fi;
    }
    while(u != v) {
        maxi = max(maxi, pai[u].se);
        u = pai[u].fi;
        maxi = max(maxi, pai[v].se);
        v = pai[v].fi;
    }
    return maxi;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    int n, m, u, v, w;
    cin >> n >> m;
    loop(i, 0, n+1) paiUF[i] = i;
    loop(i, 0, m) {
        cin >> u >> v >> w;
        edges.pb({w, u, v});
        unorderedEdges.pb({w, u, v});
    }
    int ans = krustal();
    depth[1] = 0;
    dfs(1);
    loop(i, 0, m) {
        tie(w, u, v) = unorderedEdges[i];
        int la = lca(u, v);
        cout << ans - lca(u, v) + w << '\n';
    }
}


//B - Minimum spanning tree for each edge
//Assunto: LCA/ Krustal/ Union Find;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 200050
#define MOD 1000000007
#define LOG 25
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

vector<tuple<int, int, int>> edges, unorderedEdges;
vector<ii> grafo[MAX];
vector<int> paiUF(MAX), peso(MAX, 1), depth(MAX, -1);
int parent[LOG][MAX];
ll maxE[LOG][MAX];

int find(int x) {
    while(x != paiUF[x]) x = paiUF[x];
    return x;
}

void join(int a, int b) {
    a = find(a);
    b = find(b);
    if(peso[a] < peso[b]) swap(a, b);
    peso[a] += peso[b];
    paiUF[b] = a;
}

ll krustal() {
    ll ans = 0;
    sort(all(edges));
    loop(i, 0, edges.size()) {
        int peso, u, v;
        tie(peso, u, v) = edges[i];
        if(find(u) != find(v)) {
            join(u, v);
            ans += peso;
            grafo[u].pb({v, peso});
            grafo[v].pb({u, peso});
        }
    }
    return ans;
}

void dfs(int no) {
    for(auto p : grafo[no]) {
        int viz = p.fi;
        if(depth[viz] == -1) {
            depth[viz] = depth[no] + 1;
            parent[0][viz] = no;
            maxE[0][viz] = p.se;
            dfs(viz);
        }
    }
}

void build() {
    loop(i, 1, LOG) {
        loop(j, 0, MAX) {
            parent[i][j] = parent[i-1][parent[i-1][j]];
            maxE[i][j] = max(parent[i-1][j], parent[i-1][parent[i-1][j]]);
        }
    }
}

ll lca(int u, int v) {
    ll maxi = 0;
    if(depth[v] > depth[u]) swap(u, v);
    loopBack(i, LOG - 1, 0)
        if(depth[u] - (1 << i) >= depth[v]) {
            maxi = max(maxi, maxE[i][u]);
            u = parent[i][u];
        }
    if(u == v) return maxi;
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    loopBack(i, LOG-1, 0) {
        if(parent[i][u] != parent[i][v]) {
            maxi = max(maxi, maxE[i][u]);
            maxi = max(maxi, maxE[i][v]);
            u = parent[i][u];
            v = parent[i][v];
        }
    }
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    return maxi;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    int n, m, u, v, w;
    cin >> n >> m;
    loop(i, 0, n+1) paiUF[i] = i;
    loop(i, 0, m) {
        cin >> u >> v >> w;
        u--; v--;
        edges.pb({w, u, v});
        unorderedEdges.pb({w, u, v});
    }
    ll ans = krustal();
    depth[1] = 0;
    dfs(1);
    build();
    loop(i, 0, m) {
        tie(w, u, v) = unorderedEdges[i];
        ll la = lca(u, v);
        ll resp = ans - la + w;
        cout << resp << '\n';
    }
}


//B - Minimum spanning tree for each edge
//Assunto: LCA/ Krustal/ Union Find;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 200050
#define MOD 1000000007
#define LOG 25
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

vector<tuple<int, int, int>> edges, unorderedEdges;
vector<ii> grafo[MAX];
vector<int> paiUF(MAX), peso(MAX, 1), depth(MAX, -1);
int parent[LOG][MAX];
ll maxE[LOG][MAX];

int find(int x) {
    while(x != paiUF[x]) x = paiUF[x];
    return x;
}

int join(int a, int b) {
    a = find(a);
    b = find(b);
    if(peso[a] < peso[b]) swap(a, b);
    peso[a] += peso[b];
    paiUF[b] = a;
}

ll krustal() {
    ll ans = 0;
    sort(all(edges));
    loop(i, 0, edges.size()) {
        int peso, u, v;
        tie(peso, u, v) = edges[i];
        if(find(u) != find(v)) {
            join(u, v);
            ans += peso;
            grafo[u].pb({v, peso});
            grafo[v].pb({u, peso});
        }
    }
    return ans;
}

void dfs(int no) {
    for(auto p : grafo[no]) {
        int viz = p.fi;
        if(depth[viz] == -1) {
            depth[viz] = depth[no] + 1;
            parent[0][viz] = no;
            maxE[0][viz] = p.se;
            dfs(viz);
        }
    }
}

void build() {
    loop(i, 1, LOG) {
        loop(j, 0, MAX) {
            parent[i][j] = parent[i-1][parent[i-1][j]];
            maxE[i][j] = max(parent[i-1][j], parent[i-1][parent[i-1][j]]);
        }
    }
}

ll lca(int u, int v) {
    ll maxi = 0;
    if(depth[v] > depth[u]) swap(u, v);
    loopBack(i, LOG - 1, 0)
        if(depth[u] - (1 << i) >= depth[v]) {
            maxi = max(maxi, maxE[i][u]);
            u = parent[i][u];
        }
    if(u == v) return maxi;
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    loopBack(i, LOG-1, 0) {
        if(parent[i][u] != parent[i][v]) {
            maxi = max(maxi, maxE[i][u]);
            maxi = max(maxi, maxE[i][v]);
            u = parent[i][u];
            v = parent[i][v];
        }
    }
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    return maxi;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    int n, m, u, v, w;
    cin >> n >> m;
    loop(i, 0, n+1) paiUF[i] = i;
    loop(i, 0, m) {
        cin >> u >> v >> w;
        u--; v--;
        edges.pb({w, u, v});
        unorderedEdges.pb({w, u, v});
    }
    ll ans = krustal();
    depth[1] = 0;
    dfs(1);
    build();
    loop(i, 0, m) {
        tie(w, u, v) = unorderedEdges[i];
        ll la = lca(u, v);
        cout << ans - la + w << '\n';
    }
}


//B - Minimum spanning tree for each edge
//Assunto: LCA/ Krustal/ Union Find;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 200050
#define MOD 1000000007
#define LOG 25
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

vector<tuple<int, int, int>> edges, unorderedEdges;
vector<ii> grafo[MAX];
vector<int> paiUF(MAX), peso(MAX, 1), depth(MAX, -1);
int parent[LOG][MAX];
ll maxE[LOG][MAX];

int find(int x) {
    while(x != paiUF[x]) x = paiUF[x];
    return x;
}

void join(int a, int b) {
    a = find(a);
    b = find(b);
    if(peso[a] < peso[b]) swap(a, b);
    peso[a] += peso[b];
    paiUF[b] = a;
}

ll krustal() {
    ll ans = 0;
    sort(all(edges));
    loop(i, 0, edges.size()) {
        int peso, u, v;
        tie(peso, u, v) = edges[i];
        if(find(u) != find(v)) {
            join(u, v);
            ans += peso;
            grafo[u].pb({v, peso});
            grafo[v].pb({u, peso});
        }
    }
    return ans;
}

void dfs(int no) {
    for(auto p : grafo[no]) {
        int viz = p.fi;
        if(depth[viz] == -1) {
            depth[viz] = depth[no] + 1;
            parent[0][viz] = no;
            maxE[0][viz] = p.se;
            dfs(viz);
        }
    }
}

void build() {
    loop(i, 1, LOG) {
        loop(j, 0, MAX) {
            parent[i][j] = parent[i-1][parent[i-1][j]];
            maxE[i][j] = max(parent[i-1][j], parent[i-1][parent[i-1][j]]);
        }
    }
}

ll lca(int u, int v) {
    ll maxi = 0;
    if(depth[v] > depth[u]) swap(u, v);
    loopBack(i, LOG - 1, 0)
        if(depth[u] - (1 << i) >= depth[v]) {
            maxi = max(maxi, maxE[i][u]);
            u = parent[i][u];
        }
    if(u == v) return maxi;
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    loopBack(i, LOG-1, 0) {
        if(parent[i][u] != parent[i][v]) {
            maxi = max(maxi, maxE[i][u]);
            u = parent[i][u];
            maxi = max(maxi, maxE[i][v]);
            v = parent[i][v];
        }
    }
    maxi = max({maxi, maxE[0][u], maxE[0][v]});
    return maxi;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    int n, m, u, v, w;
    cin >> n >> m;
    loop(i, 0, n+1) paiUF[i] = i;
    loop(i, 0, m) {
        cin >> u >> v >> w;
        u--; v--;
        edges.pb({w, u, v});
        unorderedEdges.pb({w, u, v});
    }
    ll ans = krustal();
    depth[0] = 0;
    dfs(0);
    build();
    loop(i, 0, m) {
        tie(w, u, v) = unorderedEdges[i];
        ll la = lca(u, v);
        ll resp = ans - la + w;
        cout << resp << '\n';
    }
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node)
{
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n)
{
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0; i<siz; i++)
    {
        ll child=edj[n][i].first;
        if(color[child]==false)
        {
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=edj[n][i].second;
            //cout<<sparse[child][0]<<" "<<mx[child][0]<<" x\n";
            dfs(child);
        }
    }
}
void lca(ll n)
{
    for(ll i=0; i<=n; i++)
    {
        color[i]=false;
        for(ll j=0; (1<<j)<=n; j++)
        {
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    label[1]=0;
    dfs(1);
    for(ll j=1; (1<<j)<=n; j++)
    {
        for(ll i=1; i<=n; i++)
        {
            sparse[i][j]=sparse[sparse[i][j-1]][j-1];
            mx[i][j]=max(mx[sparse[i][j-1]][j-1],mx[i][j-1]);
        }
    }
}
ll query(ll u,ll v)
{
    if(label[u]<label[v])swap(u,v);
    ll ma=max(mx[u][0],mx[v][0]);
    ll lg;
    for(lg=0; (1<<lg)<=label[u]; lg++);
    lg--;
    if(label[u]!=label[v])
    {
        for(ll i=lg; i>=0; i--)
        {
            if(label[u]-(1<<i)>=label[v])
            {
                u=sparse[u][i];
                ma=max(ma,mx[u][i]);
            }
        }
    }
    if(u==v)
    {
        return ma;
    }
    for(ll i=lg; i>=0; i--)
    {
        if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i])
        {
            ma=max(ma,mx[u][i]);
            ma=max(ma,mx[v][i]);
            u=sparse[u][i];
            v=sparse[v][i];

        }
    }
    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main()
{

    ll n,e;
    cin>>n>>e;
    for(ll i=0; i<=n; i++)rep[i]=i;
    for(ll i=0; i<e; i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0; i<e; i++)
    {
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v)
        {
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else
        {
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0; i<e; i++)
    {
        if(ar[i]==1)
        {
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0; i<ss; i++)
    {
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0; i<e; i++)
    {
        cout<<ar[i]<<"\n";
    }
    return 0;
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node)
{
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n)
{
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0; i<siz; i++)
    {
        ll child=edj[n][i].first;
        if(color[child]==false)
        {
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=edj[n][i].second;
            //cout<<sparse[child][0]<<" "<<mx[child][0]<<" x\n";
            dfs(child);
        }
    }
}
void lca(ll n)
{
    for(ll i=0; i<=n; i++)
    {
        color[i]=false;
        for(ll j=0; (1<<j)<=n; j++)
        {
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    label[1]=0;
    sparse[1][0]=1;
    dfs(1);
    for(ll j=1; (1<<j)<=n; j++)
    {
        for(ll i=1; i<=n; i++)
        {
            sparse[i][j]=sparse[sparse[i][j-1]][j-1];
            mx[i][j]=max(mx[sparse[i][j-1]][j-1],mx[i][j-1]);
        }
    }
}
ll query(ll u,ll v)
{
    if(label[u]<label[v])swap(u,v);
    ll ma=max(mx[u][0],mx[v][0]);
    ll lg;
    for(lg=0; (1<<lg)<=label[u]; lg++);
    lg--;
    if(label[u]!=label[v])
    {
        for(ll i=lg; i>=0; i--)
        {
            if(label[u]-(1<<i)>=label[v])
            {
                ma=max(ma,mx[u][i]);
                u=sparse[u][i];

            }
        }
    }
//    if(u==v)
//    {
//        return ma;
//    }
    if(u!=v){
        for(ll i=lg; i>=0; i--)
        {
            if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i])
            {
                ma=max(ma,mx[u][i]);
                ma=max(ma,mx[v][i]);
                u=sparse[u][i];
                v=sparse[v][i];

            }
        }
    }

    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main()
{

    ll n,e;
    cin>>n>>e;
    for(ll i=0; i<=n; i++)rep[i]=i;
    for(ll i=0; i<e; i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0; i<e; i++)
    {
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v)
        {
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else
        {
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0; i<e; i++)
    {
        if(ar[i]==1)
        {
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0; i<ss; i++)
    {
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0; i<e; i++)
    {
        cout<<ar[i]<<"\n";
    }
    return 0;
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node)
{
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n)
{
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0; i<siz; i++)
    {
        ll child=edj[n][i].first;
        if(color[child]==false)
        {
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=edj[n][i].second;
            //cout<<sparse[child][0]<<" "<<mx[child][0]<<" x\n";
            dfs(child);
        }
    }
}
void lca(ll n)
{
    for(ll i=0; i<=n; i++)
    {
        color[i]=false;
        for(ll j=0; (1<<j)<=n; j++)
        {
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    label[1]=0;
    sparse[1][0]=1;
    dfs(1);
    for(ll j=1; (1<<j)<=n; j++)
    {
        for(ll i=1; i<=n; i++)
        {
            sparse[i][j]=sparse[sparse[i][j-1]][j-1];
            mx[i][j]=max(mx[sparse[i][j-1]][j-1],mx[i][j-1]);
        }
    }
}
ll query(ll u,ll v)
{
    if(label[u]<label[v])swap(u,v);
    ll ma=mx[u][0];
    ll lg;
    for(lg=0; (1<<lg)<=label[u]; lg++);
    lg--;
    if(label[u]!=label[v])
    {
        for(ll i=lg; i>=0; i--)
        {
            if(label[u]-(1<<i)>=label[v])
            {
                ma=max(ma,mx[u][i]);
                u=sparse[u][i];

            }
        }
    }
    if(u==v)
    {
        return ma;
    }
    if(u!=v)
    {
        for(ll i=lg; i>=0; i--)
        {
            if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i])
            {
                ma=max(ma,mx[u][i]);
                ma=max(ma,mx[v][i]);
                u=sparse[u][i];
                v=sparse[v][i];

            }
        }
    }

    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main()
{

    ll n,e;
    cin>>n>>e;
    for(ll i=0; i<=n; i++)rep[i]=i;
    for(ll i=0; i<e; i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0; i<e; i++)
    {
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v)
        {
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else
        {
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0; i<e; i++)
    {
        if(ar[i]==1)
        {
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0; i<ss; i++)
    {
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0; i<e; i++)
    {
        cout<<ar[i]<<"\n";
    }
    return 0;
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node)
{
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n)
{
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0; i<siz; i++)
    {
        ll child=edj[n][i].first;
        if(color[child]==false)
        {
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=edj[n][i].second;
            //cout<<sparse[child][0]<<" "<<mx[child][0]<<" x\n";
            dfs(child);
        }
    }
}
void lca(ll n)
{
    for(ll i=0; i<=n; i++)
    {
        color[i]=false;
        for(ll j=0; (1<<j)<=n; j++)
        {
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    label[1]=0;
    sparse[1][0]=1;
    dfs(1);
    for(ll j=1; (1<<j)<=n; j++)
    {
        for(ll i=1; i<=n; i++)
        {
            sparse[i][j]=sparse[sparse[i][j-1]][j-1];
            mx[i][j]=max(mx[sparse[i][j-1]][j-1],mx[i][j-1]);
        }
    }
}
ll query(ll u,ll v)
{
    if(label[u]<label[v])swap(u,v);
    ll ma=mx[u][0];
    ll lg;
    for(lg=0; (1<<lg)<=label[u]; lg++);
    lg--;
    if(label[u]!=label[v])
    {
        for(ll i=lg; i>=0; i--)
        {
            if(label[u]-(1<<i)>=label[v])
            {
                ma=max(ma,mx[u][i]);
                u=sparse[u][i];

            }
        }
    }
    if(u==v)
    {
        return ma;
    }
    if(u!=v)
    {
        for(ll i=lg; i>=0; i--)
        {
            if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i])
            {
                ma=max(ma,mx[u][i]);
                ma=max(ma,mx[v][i]);
                u=sparse[u][i];
                v=sparse[v][i];

            }
        }
    }

    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(false);cout.tie(false);
    ll n,e;
    cin>>n>>e;
    for(ll i=0; i<=n; i++)rep[i]=i;
    for(ll i=0; i<e; i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0; i<e; i++)
    {
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v)
        {
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else
        {
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0; i<e; i++)
    {
        if(ar[i]==1)
        {
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0; i<ss; i++)
    {
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0; i<e; i++)
    {
        cout<<ar[i]<<"\n";
    }
    return 0;
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node)
{
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n)
{
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0; i<siz; i++)
    {
        ll child=edj[n][i].first;
        if(color[child]==false)
        {
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=edj[n][i].second;
            //cout<<sparse[child][0]<<" "<<mx[child][0]<<" x\n";
            dfs(child);
        }
    }
}
void lca(ll n)
{
    for(ll i=0; i<=n; i++)
    {
        color[i]=false;
        for(ll j=0; (1<<j)<=n; j++)
        {
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    label[1]=0;
    sparse[1][0]=1;
    dfs(1);
    for(ll j=1; (1<<j)<=n; j++)
    {
        for(ll i=1; i<=n; i++)
        {
            sparse[i][j]=sparse[sparse[i][j-1]][j-1];
            mx[i][j]=max(mx[sparse[i][j-1]][j-1],mx[i][j-1]);
        }
    }
}
ll query(ll u,ll v)
{
    if(label[u]<label[v])swap(u,v);
    ll ma=max(mx[u][0],mx[v][0]);
    ll lg;
    for(lg=0; (1<<lg)<=label[u]; lg++);
    lg--;
    if(label[u]!=label[v])
    {
        for(ll i=lg; i>=0; i--)
        {
            if(label[u]-(1<<i)>=label[v])
            {
                u=sparse[u][i];
                ma=max(ma,mx[u][i]);
            }
        }
    }
    if(u==v)
    {
        return ma;
    }
    for(ll i=lg; i>=0; i--)
    {
        if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i])
        {
            ma=max(ma,mx[u][i]);
            ma=max(ma,mx[v][i]);
            u=sparse[u][i];
            v=sparse[v][i];

        }
    }
    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main()
{

    ll n,e;
    cin>>n>>e;
    for(ll i=0; i<=n; i++)rep[i]=i;
    for(ll i=0; i<e; i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0; i<e; i++)
    {
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v)
        {
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else
        {
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0; i<e; i++)
    {
        if(ar[i]==1)
        {
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0; i<ss; i++)
    {
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0; i<e; i++)
    {
        cout<<ar[i]<<"\n";
    }
    return 0;
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node){
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n){
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0;i<siz;i++){
        ll child=edj[n][i].first;
        ll we=edj[n][i].second;
        if(color[child]==false){
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=we;
            dfs(child);
        }
    }
}
void lca(ll n){
    for(ll i=0;i<n;i++){
        for(ll j=0;(1<<j)<=n;j++){
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    dfs(1);
    for(ll i=1;(1<<i)<=n;i++){
        for(ll j=1;j<=n;j++){
            sparse[i][j]=sparse[sparse[j][i-1]][i-1];
            mx[i][j]=max(mx[mx[j][i-1]][i-1],sparse[j][i-1]);
        }
    }
}
ll query(ll u,ll v){
    if(label[u]<label[v])swap(u,v);
    ll ma=max(mx[u][0],mx[v][0]);
    ll lg;
    for(lg=0;(1<<lg)<=label[u];lg++);
    lg--;
    if(label[u]!=label[v]){
        for(ll i=lg;i>=0;i--){
            if(label[u]-(1<<i)>=label[v]){
                u=sparse[u][i];
                ma=max(ma,mx[u][i]);
            }
        }
    }
    if(u==v){
        return ma;
    }
    for(ll i=lg;i>=0;i--){
        if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i]){
            ma=max(ma,mx[u][i]);
            ma=max(ma,mx[v][i]);
            u=sparse[u][i];
            v=sparse[v][i];

        }
    }
    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main(){

    ll n,e;
    cin>>n>>e;
    for(ll i=0;i<=n;i++)rep[i]=i;
    for(ll i=0;i<e;i++){
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0;i<e;i++){
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v){
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else{
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0;i<e;i++){
        if(ar[i]==1){
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0;i<ss;i++){
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0;i<e;i++){
        cout<<ar[i]<<"\n";
    }
    return 0;
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node)
{
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n)
{
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0; i<siz; i++)
    {
        ll child=edj[n][i].first;
        if(color[child]==false)
        {
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=edj[n][i].second;
            //cout<<sparse[child][0]<<" "<<mx[child][0]<<" x\n";
            dfs(child);
        }
    }
}
void lca(ll n)
{
    for(ll i=0; i<=n; i++)
    {
        color[i]=false;
        for(ll j=0; (1<<j)<=n; j++)
        {
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    label[1]=0;
    sparse[1][0]=1;
    dfs(1);
    for(ll j=1; (1<<j)<=n; j++)
    {
        for(ll i=1; i<=n; i++)
        {
            sparse[i][j]=sparse[sparse[i][j-1]][j-1];
            mx[i][j]=max(mx[sparse[i][j-1]][j-1],mx[i][j-1]);
        }
    }
}
ll query(ll u,ll v)
{
    if(label[u]<label[v])swap(u,v);
    ll ma=mx[u][0];
    ll lg;
    for(lg=0; (1<<lg)<=label[u]; lg++);
    lg--;
    if(label[u]!=label[v])
    {
        for(ll i=lg; i>=0; i--)
        {
            if(label[u]-(1<<i)>=label[v])
            {
                ma=max(ma,mx[u][i]);
                u=sparse[u][i];

            }
        }
    }
//    if(u==v)
//    {
//        return ma;
//    }
    if(u!=v){
        for(ll i=lg; i>=0; i--)
        {
            if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i])
            {
                ma=max(ma,mx[u][i]);
                ma=max(ma,mx[v][i]);
                u=sparse[u][i];
                v=sparse[v][i];

            }
        }
    }

    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main()
{

    ll n,e;
    cin>>n>>e;
    for(ll i=0; i<=n; i++)rep[i]=i;
    for(ll i=0; i<e; i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0; i<e; i++)
    {
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v)
        {
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else
        {
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0; i<e; i++)
    {
        if(ar[i]==1)
        {
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0; i<ss; i++)
    {
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0; i<e; i++)
    {
        cout<<ar[i]<<"\n";
    }
    return 0;
}


/*
    Sk arman Hossain
    University of Barisal

    Problem : Second Minimum Spanning Tree
    Solution : Kruskal + LCA
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200010
ll rep[N];
ll Find(ll node)
{
    return (rep[node]==node?node:rep[node]=Find(rep[node]));
}
vector<pair<pair<ll,ll>,pair<ll,ll> > > V;
vector<pair<pair<ll,ll>,pair<ll,ll> > > unvisited_edge;
vector< pair<ll,ll> >edj[N];
ll ar[N],label[N];
ll sparse[N][22];
ll mx[N][22];
bitset<N>color;
void dfs(ll n)
{
    color[n]=true;
    ll siz=edj[n].size();
    for(ll i=0; i<siz; i++)
    {
        ll child=edj[n][i].first;
        if(color[child]==false)
        {
            label[child]=label[n]+1;
            color[child]=true;
            sparse[child][0]=n;
            mx[child][0]=edj[n][i].second;
            //cout<<sparse[child][0]<<" "<<mx[child][0]<<" x\n";
            dfs(child);
        }
    }
}
void lca(ll n)
{
    for(ll i=0; i<=n; i++)
    {
        color[i]=false;
        for(ll j=0; (1<<j)<=n; j++)
        {
            sparse[i][j]=-1;
            mx[i][j]=-1;
        }
    }
    label[1]=0;
    sparse[1][0]=1;
    dfs(1);
    for(ll j=1; (1<<j)<=n; j++)
    {
        for(ll i=1; i<=n; i++)
        {
            sparse[i][j]=sparse[sparse[i][j-1]][j-1];
            mx[i][j]=max(mx[sparse[i][j-1]][j-1],mx[i][j-1]);
        }
    }
}
ll query(ll u,ll v)
{
    if(label[u]<label[v])swap(u,v);
    ll ma=mx[u][0];
    ll lg;
    for(lg=0; (1<<lg)<=label[u]; lg++);
    lg--;
    if(label[u]!=label[v])
    {
        for(ll i=lg; i>=0; i--)
        {
            if(label[u]-(1<<i)>=label[v])
            {
                ma=max(ma,mx[u][i]);
                u=sparse[u][i];

            }
        }
    }
    if(u==v)
    {
        return ma;
    }
    if(u!=v)
    {
        for(ll i=lg; i>=0; i--)
        {
            if(sparse[u][i]!=-1&&sparse[u][i]!=sparse[v][i])
            {
                ma=max(ma,mx[u][i]);
                ma=max(ma,mx[v][i]);
                u=sparse[u][i];
                v=sparse[v][i];

            }
        }
    }

    ma=max(ma,mx[u][0]);
    ma=max(ma,mx[v][0]);
    return ma;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,e;
    cin>>n>>e;
    for(ll i=0; i<=n; i++)rep[i]=i;
    for(ll i=0; i<e; i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        V.push_back({{w,u},{v,i}});
    }
    sort(V.begin(),V.end());
    ll sum=0;
    for(ll i=0; i<e; i++)
    {
        ll u=Find(V[i].first.second);
        ll v=Find(V[i].second.first);
        if(u!=v)
        {
            ar[V[i].second.second]=1;
            sum+=V[i].first.first;
            rep[u]=v;
            edj[V[i].first.second].push_back({V[i].second.first,V[i].first.first});
            edj[V[i].second.first].push_back({V[i].first.second,V[i].first.first});
        }
        else
        {
            unvisited_edge.push_back(V[i]);
        }
    }
    lca(n);
    for(ll i=0; i<e; i++)
    {
        if(ar[i]==1)
        {
            ar[i]=sum;
        }
    }
    ll ss=unvisited_edge.size();
    for(ll i=0; i<ss; i++)
    {
        ll tm=query(unvisited_edge[i].first.second,unvisited_edge[i].second.first);
        //cout<<tm<<" te\n";
        ar[unvisited_edge[i].second.second]=sum+(unvisited_edge[i].first.first-tm);
    }
    for(ll i=0; i<e; i++)
    {
        cout<<ar[i]<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define y second
#define x first
const ll M= 1000000007;
vector<ll>adj[100001];
ll par[100001][30];
ll mx[100001][30];
ll depth[100001];
map<pair<ll,ll>,ll>w;
ll n;
void dfs1(ll c,ll p,ll d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(ll k=1;k<30;k++)
		for(ll i=1;i<=n;i++)
		{
			ll mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

ll lca(ll u,ll v)
{
	if(depth[u]>depth[v])swap(u,v);
	ll dif=depth[v]-depth[u];
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(ll bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

ll mx_par(ll c,ll p)
{
	ll dif=depth[c]-depth[p];
	ll mv=-1;
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

ll mx_path(ll u,ll v)
{
	ll l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	ll m;
	cin>>n>>m;
	vector<int>adj1[n+1];
	if(n==1){return;}
	pair<ll,pair<ll,ll>>egd[m];
	map<pair<int,int>,int>w1;
	for(ll i=0;i<m;i++)
	{
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
		adj1[egd[i].second.first].pb(egd[i].second.second);
		adj1[egd[i].second.second].pb(egd[i].second.first);
		w1[{egd[i].second.first,egd[i].second.second}]=w1[{egd[i].second.second,egd[i].second.first}]=egd[i].first;
	}
	vector<pair<ll,pair<ll,ll>>>taken;
	//MST
	set<pair<int,pair<int,int>>>st;
	set<int>vert;
	vert.insert(1);
	for(auto x:adj1[1])st.insert({w1[{1,x}],{1,x}});
	while(!st.empty() and vert.size()!=n)
	{
		pair<int,pair<int,int>>p1=*st.begin();st.erase(st.begin());
		int n1=p1.second.first,n2=p1.second.second;
		if(vert.find(n1)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n1);
			for(auto x:adj1[n1])
				st.insert({w1[{n1,x}],{n1,x}});
		}
		else if(vert.find(n2)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n2);
			for(auto x:adj1[n2])
				st.insert({w1[{n2,x}],{n2,x}});
		}
	}

	//
	ll mst=0;
	for(auto x:taken)
	{
		mst+=x.first;
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	// cout<<mst<<endl;
	init();
	for(ll i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define y second
#define x first
const ll M= 1000000007;
vector<ll>adj[100001];
ll par[100001][30];
ll mx[100001][30];
ll depth[100001];
map<pair<ll,ll>,ll>w;
ll n;
void dfs1(ll c,ll p,ll d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(ll k=1;k<30;k++)
		for(ll i=1;i<=n;i++)
		{
			ll mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

ll lca(ll u,ll v)
{
	if(depth[u]>depth[v])swap(u,v);
	ll dif=depth[v]-depth[u];
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(ll bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

ll mx_par(ll c,ll p)
{
	ll dif=depth[c]-depth[p];
	ll mv=-1;
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

ll mx_path(ll u,ll v)
{
	ll l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	ll m;
	cin>>n>>m;
	if(n==1){return;}
	pair<ll,pair<ll,ll>>egd[m];
	for(ll i=0;i<m;i++)
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
	set<pair<ll,pair<ll,ll>>>st,taken;
	for(ll i=0;i<m;i++)st.insert(egd[i]);

	bool vis[n+1]={0};
	ll nodes=0;

	while(nodes<n)
	{
		pair<ll,ll>p1=(*st.begin()).second;
		taken.insert(*st.begin());
		if(!vis[p1.first] and !vis[p1.second])
			nodes+=2;
		else if(!vis[p1.first] or !vis[p1.second])
			nodes+=1;
		else
			taken.erase(*st.begin());
		vis[p1.first]=vis[p1.second]=1;
		st.erase(st.begin());
	}
	ll mst=0;
	for(auto x:taken)mst+=x.first;

	for(auto x:taken)
	{
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	init();
	for(ll i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define y second
#define x first
const ll M= 1000000007;
vector<int>adj[100001];
int par[100001][30];
int mx[100001][30];
int depth[100001];
map<pair<int,int>,int>w;
int n;
void dfs1(int c,int p,int d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(int k=1;k<30;k++)
		for(int i=1;i<=n;i++)
		{
			int mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

int lca(int u,int v)
{
	if(depth[u]>depth[v])swap(u,v);
	int dif=depth[v]-depth[u];
	for(int bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(int bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

int mx_par(int c,int p)
{
	int dif=depth[c]-depth[p];
	int mv=-1;
	for(int bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

int mx_path(int u,int v)
{
	int l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	int m;
	cin>>n>>m;
	pair<int,pair<int,int>>egd[m];
	for(int i=0;i<m;i++)
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
	set<pair<int,pair<int,int>>>st,taken;
	for(int i=0;i<m;i++)st.insert(egd[i]);

	bool vis[n+1]={0};
	int nodes=0;

	while(nodes<n)
	{
		pair<int,int>p1=(*st.begin()).second;
		taken.insert(*st.begin());
		if(!vis[p1.first] and !vis[p1.second])
			nodes+=2;
		else if(!vis[p1.first] or !vis[p1.second])
			nodes+=1;
		else
			taken.erase(*st.begin());
		vis[p1.first]=vis[p1.second]=1;
		st.erase(st.begin());
	}
	int mst=0;
	for(auto x:taken)mst+=x.first;

	for(auto x:taken)
	{
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	init();
	for(int i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define y second
#define x first
const ll M= 1000000007;
vector<int>adj[100001];
int par[100001][30];
int mx[100001][30];
int depth[100001];
map<pair<int,int>,int>w;
int n;
void dfs1(int c,int p,int d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(int k=1;k<30;k++)
		for(int i=1;i<=n;i++)
		{
			int mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

int lca(int u,int v)
{
	if(depth[u]>depth[v])swap(u,v);
	int dif=depth[v]-depth[u];
	for(int bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(int bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

int mx_par(int c,int p)
{
	int dif=depth[c]-depth[p];
	int mv=-1;
	for(int bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

int mx_path(int u,int v)
{
	int l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	int m;
	cin>>n>>m;
	if(n==0){cout<<0<<endl;return;}
	pair<int,pair<int,int>>egd[m];
	for(int i=0;i<m;i++)
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
	set<pair<int,pair<int,int>>>st,taken;
	for(int i=0;i<m;i++)st.insert(egd[i]);

	bool vis[n+1]={0};
	int nodes=0;

	while(nodes<n)
	{
		pair<int,int>p1=(*st.begin()).second;
		taken.insert(*st.begin());
		if(!vis[p1.first] and !vis[p1.second])
			nodes+=2;
		else if(!vis[p1.first] or !vis[p1.second])
			nodes+=1;
		else
			taken.erase(*st.begin());
		vis[p1.first]=vis[p1.second]=1;
		st.erase(st.begin());
	}
	int mst=0;
	for(auto x:taken)mst+=x.first;

	for(auto x:taken)
	{
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	init();
	for(int i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
const ll M= 1000000007;
vector<ll>adj[100001];
ll par[100001][30];
ll mx[100001][30];
ll depth[100001];
map<pair<ll,ll>,ll>w;
ll n;
void dfs1(ll c,ll p,ll d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(ll k=1;k<30;k++)
		for(ll i=1;i<=n;i++)
		{
			ll mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

ll lca(ll u,ll v)
{
	if(depth[u]>depth[v])swap(u,v);
	ll dif=depth[v]-depth[u];
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(ll bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

ll mx_par(ll c,ll p)
{
	ll dif=depth[c]-depth[p];
	ll mv=-1;
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

ll mx_path(ll u,ll v)
{
	ll l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	ll m;
	cin>>n>>m;
	vector<int>adj1[n+1];
	if(n==1){return;}
	pair<ll,pair<ll,ll>>egd[m];
	map<pair<int,int>,int>w1;
	for(ll i=0;i<m;i++)
	{
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
		adj1[egd[i].second.first].pb(egd[i].second.second);
		adj1[egd[i].second.second].pb(egd[i].second.first);
		w1[{egd[i].second.first,egd[i].second.second}]=w1[{egd[i].second.second,egd[i].second.first}]=egd[i].first;
	}
	vector<pair<ll,pair<ll,ll>>>taken;
	//MST
	set<pair<int,pair<int,int>>>st;
	unordered_set<int>vert;
	vert.insert(1);
	for(auto x:adj1[1])st.insert({w1[{1,x}],{1,x}});
	while(!st.empty() and vert.size()!=n)
	{
		pair<int,pair<int,int>>p1=*st.begin();st.erase(st.begin());
		int n1=p1.second.first,n2=p1.second.second;
		if(vert.find(n1)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n1);
			for(auto x:adj1[n1])
				if(vert.find(x)==vert.end())
					st.insert({w1[{n1,x}],{n1,x}});
		}
		else if(vert.find(n2)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n2);
			for(auto x:adj1[n2])
				if(vert.find(x)==vert.end())
					st.insert({w1[{n2,x}],{n2,x}});
		}
	}

	//
	ll mst=0;
	for(auto x:taken)
	{
		mst+=x.first;
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	// cout<<mst<<endl;
	init();
	for(ll i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define y second
#define x first
const ll M= 1000000007;
vector<ll>adj[100001];
ll par[100001][30];
ll mx[100001][30];
ll depth[100001];
map<pair<ll,ll>,ll>w;
ll n;
void dfs1(ll c,ll p,ll d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(ll k=1;k<30;k++)
		for(ll i=1;i<=n;i++)
		{
			ll mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

ll lca(ll u,ll v)
{
	if(depth[u]>depth[v])swap(u,v);
	ll dif=depth[v]-depth[u];
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(ll bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

ll mx_par(ll c,ll p)
{
	ll dif=depth[c]-depth[p];
	ll mv=-1;
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

ll mx_path(ll u,ll v)
{
	ll l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	ll m;
	cin>>n>>m;
	vector<int>adj1[n+1];
	if(n==1){return;}
	pair<ll,pair<ll,ll>>egd[m];
	map<pair<int,int>,int>w1;
	for(ll i=0;i<m;i++)
	{
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
		adj1[egd[i].second.first].pb(egd[i].second.second);
		adj1[egd[i].second.second].pb(egd[i].second.first);
		w1[{egd[i].second.first,egd[i].second.second}]=w1[{egd[i].second.second,egd[i].second.first}]=egd[i].first;
	}
	vector<pair<ll,pair<ll,ll>>>taken;
	//MST
	set<pair<int,pair<int,int>>>st;
	set<int>vert;
	vert.insert(1);
	for(auto x:adj1[1])st.insert({w1[{1,x}],{1,x}});
	while(!st.empty() and vert.size()!=n)
	{
		pair<int,pair<int,int>>p1=*st.begin();st.erase(st.begin());
		int n1=p1.second.first,n2=p1.second.second;
		if(vert.find(n1)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n1);
			for(auto x:adj1[n1])
				st.insert({w1[{n1,x}],{n1,x}});
		}
		else if(vert.find(n2)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n2);
			for(auto x:adj1[n2])
				st.insert({w1[{n2,x}],{n2,x}});
		}
	}

	//
	int mst=0;
	for(auto x:taken)
	{
		mst+=x.first;
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	// cout<<mst<<endl;
	init();
	for(ll i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define y second
#define x first
const ll M= 1000000007;
vector<int>adj[100001];
int par[100001][30];
int mx[100001][30];
int depth[100001];
map<pair<int,int>,int>w;
int n;
void dfs1(int c,int p,int d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(int k=1;k<30;k++)
		for(int i=1;i<=n;i++)
		{
			int mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

int lca(int u,int v)
{
	if(depth[u]>depth[v])swap(u,v);
	int dif=depth[v]-depth[u];
	for(int bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(int bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

int mx_par(int c,int p)
{
	int dif=depth[c]-depth[p];
	int mv=-1;
	for(int bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

int mx_path(int u,int v)
{
	int l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	int m;
	cin>>n>>m;
	if(n==0){return;}
	pair<int,pair<int,int>>egd[m];
	for(int i=0;i<m;i++)
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
	set<pair<int,pair<int,int>>>st,taken;
	for(int i=0;i<m;i++)st.insert(egd[i]);

	bool vis[n+1]={0};
	int nodes=0;

	while(nodes<n)
	{
		pair<int,int>p1=(*st.begin()).second;
		taken.insert(*st.begin());
		if(!vis[p1.first] and !vis[p1.second])
			nodes+=2;
		else if(!vis[p1.first] or !vis[p1.second])
			nodes+=1;
		else
			taken.erase(*st.begin());
		vis[p1.first]=vis[p1.second]=1;
		st.erase(st.begin());
	}
	int mst=0;
	for(auto x:taken)mst+=x.first;

	for(auto x:taken)
	{
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	init();
	for(int i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
const ll M= 1000000007;
vector<ll>adj[100001];
ll par[100001][30];
ll mx[100001][30];
ll depth[100001];
map<pair<ll,ll>,ll>w;
ll n;
void dfs1(ll c,ll p,ll d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(ll k=1;k<30;k++)
		for(ll i=1;i<=n;i++)
		{
			ll mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

ll lca(ll u,ll v)
{
	if(depth[u]>depth[v])swap(u,v);
	ll dif=depth[v]-depth[u];
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(ll bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

ll mx_par(ll c,ll p)
{
	ll dif=depth[c]-depth[p];
	ll mv=-1;
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

ll mx_path(ll u,ll v)
{
	ll l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	ll m;
	cin>>n>>m;
	vector<int>adj1[n+1];
	if(n==1){return;}
	pair<ll,pair<ll,ll>>egd[m];
	map<pair<int,int>,int>w1;
	for(ll i=0;i<m;i++)
	{
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
		adj1[egd[i].second.first].pb(egd[i].second.second);
		adj1[egd[i].second.second].pb(egd[i].second.first);
		w1[{egd[i].second.first,egd[i].second.second}]=w1[{egd[i].second.second,egd[i].second.first}]=egd[i].first;
	}
	vector<pair<ll,pair<ll,ll>>>taken;
	//MST
	set<pair<int,pair<int,int>>>st;
	unordered_set<int>vert;
	vert.insert(1);
	for(auto x:adj1[1])st.insert({w1[{1,x}],{1,x}});
	while(!st.empty() and vert.size()!=n)
	{
		pair<int,pair<int,int>>p1=*st.begin();st.erase(st.begin());
		int n1=p1.second.first,n2=p1.second.second;
		if(vert.find(n1)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n1);
			for(auto x:adj1[n1])
				if(vert.find(x)==vert.end())
					st.insert({w1[{n1,x}],{n1,x}});
		}
		else if(vert.find(n2)==vert.end())
		{
			taken.pb(p1);
			vert.insert(n2);
			for(auto x:adj1[n2])
				if(vert.find(x)==vert.end())
					st.insert({w1[{n2,x}],{n2,x}});
		}
	}

	//
	ll mst=0;
	for(auto x:taken)
	{
		mst+=x.first;
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	// cout<<mst<<endl;
	init();
	for(ll i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define y second
#define x first
const ll M= 1000000007;
vector<ll>adj[100001];
ll par[100001][30];
ll mx[100001][30];
ll depth[100001];
map<pair<ll,ll>,ll>w;
ll n;
void dfs1(ll c,ll p,ll d)
{
	par[c][0]=p;
	depth[c]=d;
	if(p!=-1)mx[c][0]=w[{c,p}];
	for(auto x:adj[c])
		if(x!=p)
			dfs1(x,c,d+1);
}

void init()
{
	dfs1(1,-1,1);
	for(ll k=1;k<30;k++)
		for(ll i=1;i<=n;i++)
		{
			ll mid=par[i][k-1];
			if(mid!=-1)
			{
				par[i][k]=par[mid][k-1];
				mx[i][k]=max(mx[i][k-1],mx[mid][k-1]);
			}
			else
				par[i][k]=mx[i][k]=-1;
		}
}

ll lca(ll u,ll v)
{
	if(depth[u]>depth[v])swap(u,v);
	ll dif=depth[v]-depth[u];
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
			v=par[v][bit];
	if(u==v)return v;
	for(ll bit=29;bit>=0;bit--)
		if(par[u][bit]!=par[v][bit])
			u=par[u][bit],v=par[v][bit];
	return par[v][0];
}

ll mx_par(ll c,ll p)
{
	ll dif=depth[c]-depth[p];
	ll mv=-1;
	for(ll bit=29;bit>=0;bit--)
		if(dif&(1<<bit))
		{
			mv=max(mv,mx[c][bit]);
			c=par[c][bit];
		}
	return mv;
}

ll mx_path(ll u,ll v)
{
	ll l=lca(u,v);
	return max(mx_par(u,l),mx_par(v,l));
}
void solve()
{
	ll m;
	cin>>n>>m;
	if(n==1){return;}
	pair<ll,pair<ll,ll>>egd[m];
	for(ll i=0;i<m;i++)
		cin>>egd[i].second.first>>egd[i].second.second>>egd[i].first;
	vector<pair<ll,pair<ll,ll>>>st,taken;
	for(ll i=0;i<m;i++)st.pb(egd[i]);
	sort(st.begin(),st.end());
	vector<int> tree_id(n+1);
	for(int i=1;i<=n;i++)
		tree_id[i]=i;
	int cost=0;
	for(int i=0;i<m;i++)
	{
		pair<ll,ll>e=st[i].second;
		if (tree_id[e.first] != tree_id[e.second]) {
        cost += st[i].first;
        taken.push_back(st[i]);

        int old_id = tree_id[e.first], new_id = tree_id[e.second];
        for (int i = 1; i <= n; i++) {
            if (tree_id[i] == old_id)
                tree_id[i] = new_id;
        }
    	}
	}
	ll mst=0;
	for(auto x:taken)mst+=x.first;
	// cout<<mst<<endl;
	for(auto x:taken)
	{
		adj[x.second.first].pb(x.second.second);adj[x.second.second].pb(x.second.first);
		w[{x.second.first,x.second.second}]=w[{x.second.second,x.second.first}]=x.first;
	}
	init();
	for(ll i=0;i<m;i++)
		cout<<mst+egd[i].first-mx_path(egd[i].second.first,egd[i].second.second)<<endl;
}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}