#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
const ll M= 1000000007;
vector<ll>adj[200001];
ll par[200001][30];
ll mx[200001][30];
ll depth[200001];
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<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==1){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
#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])
				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;

const int nmax = 2 * 1e5;
#define ll int
#define pb push_back
#define all(X) sort(X.begin(), X.end())
#define ln cout << endl
ll n;

vector<pair<ll, ll> > v;
vector<pair<ll, ll> > vec;
vector<ll> parent(nmax, -1);
vector<vector<ll> > g;
vector<vector<ll> > mx(nmax, vector<ll> (20));
vector<vector<ll> > pr(nmax, vector<ll> (20));
vector<ll> tin(nmax);
vector<ll> tout(nmax);
ll timer = 0;
map<pair<ll, ll>, ll> cost;

int cmp (pair<int, int> a, pair<int, int> b) {
	if (cost[{a.first, a.second}] < cost[{b.first, b.second}])
		return 1;
	return 0;
}

ll find (ll v) {
	if (parent[v] == v)
		return v;
	else
		return parent[v] = find(parent[v]);
}

ll unon (ll a, ll b) {
	a = find(a);
	b = find(b);
	if (a > b)
		swap(a, b);
	if (a == b)
    	return 0;
	if (rand()&1)
		parent[b] = a;
	else
	    parent[a] = b;
		return 1;

}

void dfs (ll v, ll p = 0) {
	tin[v] = timer++;
	pr[v][0] = p;
	if (cost.count({v, p}));
	mx[v][0] = cost[{v, p}];
	for (ll i = 1; i < 20; i++) {
		pr[v][i] = pr[pr[v][i - 1]][i - 1];
		mx[v][i] = max(mx[v][i - 1], mx[pr[v][i - 1]][i - 1]);
	}
	for (ll i = 0; i < g[v].size(); i++) {
		ll to = g[v][i];
		if (to == p)
			continue;
		dfs(to, v);
	}
	tout[v] = timer++;
}

ll upper (ll a, ll b) {
	if (tin[a] <= tin[b] && tout[a] >= tout[b])
		return 1;
	else
		return 0;
}

ll lca (ll a, ll b) {
	if (upper(a, b))
		return 0;
	ll ans = 0;
	for (ll i = 19; i >= 0; i--){
		if (!upper(pr[a][i], b)) {
			ans = max(ans, mx[a][i]);
			a = pr[a][i];
		}
	}
	ans = max(ans, mx[a][0]);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll m; cin >> n >> m;
	v.resize(m);
	g.resize(n);
	vec.resize(m);
	for (ll i = 0; i < m; i++) {
		ll q;
		cin >> v[i].first >> v[i].second >> q;
		v[i].first = v[i].first - 1;
		vec[i].first = v[i].first;
		v[i].second = v[i].second - 1;
		vec[i].second = v[i].second;
		cost[{v[i].first, v[i].second}] = q;
		cost[{v[i].second, v[i].first}] = q;
	}
	sort(v.begin(), v.end(), cmp);

	// cout << "OK\n";

	long long weigh_of_tree = 0;
	for (ll i = 0; i < m; i++) {
		if (parent[v[i].first] == -1)
			parent[v[i].first] = v[i].first;
		if (parent[v[i].second] == -1)
			parent[v[i].second] = v[i].second;
		if (unon(v[i].first, v[i].second) == 1) {
			//cout << v[i].first << " " << v[i].second << "\n";
			g[v[i].first].pb(v[i].second);
			g[v[i].second].pb(v[i].first);
			weigh_of_tree += cost[{v[i].first, v[i].second}];
		}
	}

	/*
	for (ll i = 0; i < n; i++) {
			cout << i + 1 << ":\n";
		for (ll j = 0; j < g[i].size(); j++) {
			cout << g[i][j] + 1 << " ";
		}
		ln;
	}
	*/

	// cout << "before dfs\n";
	dfs(0);
	// cout << "after dfs\n";

	/*for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			ll w = lca(i, j);
			ll w1 = lca(j, i);
			cout << weigh_of_tree - max(w, w1) + cost[{i, j}] << endl;
		}
	}*/

	//cout << weigh_of_tree << endl;

	for (ll i = 0; i < m; i++) {
		ll w = lca(vec[i].first, vec[i].second);
		ll w1 = lca(vec[i].second, vec[i].first);
		cout << weigh_of_tree - max(w, w1) + cost[{vec[i].first, vec[i].second}] << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int nmax = 2 * 1e5;
#define ll int
#define pb push_back
#define all(X) sort(X.begin(), X.end())
#define ln cout << endl
ll n;

vector<pair<ll, ll> > v;
vector<pair<ll, ll> > vec;
vector<ll> parent(nmax, -1);
vector<vector<ll> > g;
vector<vector<ll> > mx(nmax, vector<ll> (20));
vector<vector<ll> > pr(nmax, vector<ll> (20));
vector<ll> tin(nmax);
vector<ll> tout(nmax);
ll timer = 0;
map<pair<ll, ll>, ll> cost;

int cmp (pair<int, int> a, pair<int, int> b) {
	if (cost[{a.first, a.second}] < cost[{b.first, b.second}])
		return 1;
	return 0;
}

ll find (ll v) {
	if (parent[v] == v)
		return v;
	else
		return parent[v] = find(parent[v]);
}

ll unon (ll a, ll b) {
	a = find(a);
	b = find(b);
	if (a > b)
		swap(a, b);
	if (a == b)
    	return 0;
	if (rand()&1)
		parent[b] = a;
	else
	    parent[a] = b;
		return 1;

}

void dfs (ll v, ll p = 0) {
	tin[v] = timer++;
	pr[v][0] = p;
	if (cost.count({v, p}));
	mx[v][0] = cost[{v, p}];
	for (ll i = 1; i < 20; i++) {
		pr[v][i] = pr[pr[v][i - 1]][i - 1];
		mx[v][i] = max(mx[v][i - 1], mx[pr[v][i - 1]][i - 1]);
	}
	for (ll i = 0; i < g[v].size(); i++) {
		ll to = g[v][i];
		if (to == p)
			continue;
		dfs(to, v);
	}
	tout[v] = timer++;
}

ll upper (ll a, ll b) {
	if (tin[a] <= tin[b] && tout[a] >= tout[b])
		return 1;
	else
		return 0;
}

ll lca (ll a, ll b) {
	if (upper(a, b))
		return 0;
	ll ans = 0;
	for (ll i = 19; i >= 0; i--){
		if (!upper(pr[a][i], b)) {
			ans = max(ans, mx[a][i]);
			a = pr[a][i];
		}
	}
	ans = max(ans, mx[a][0]);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll m; cin >> n >> m;
	v.resize(m);
	g.resize(n);
	vec.resize(m);
	for (ll i = 0; i < m; i++) {
		ll q;
		cin >> v[i].first >> v[i].second >> q;
		if (v[i].first>v[i].second)
    		swap(v[i].first,v[i].second);
		v[i].first = v[i].first - 1;
		vec[i].first = v[i].first;
		v[i].second = v[i].second - 1;
		vec[i].second = v[i].second;
		cost[{v[i].first, v[i].second}] = q;
	}
	sort(v.begin(), v.end(), cmp);

	// cout << "OK\n";

	long long weigh_of_tree = 0;
	for (ll i = 0; i < m; i++) {
		if (parent[v[i].first] == -1)
			parent[v[i].first] = v[i].first;
		if (parent[v[i].second] == -1)
			parent[v[i].second] = v[i].second;
		if (unon(v[i].first, v[i].second) == 1) {
			//cout << v[i].first << " " << v[i].second << "\n";
			g[v[i].first].pb(v[i].second);
			g[v[i].second].pb(v[i].first);
			weigh_of_tree += cost[{v[i].first, v[i].second}];
		}
	}

	/*
	for (ll i = 0; i < n; i++) {
			cout << i + 1 << ":\n";
		for (ll j = 0; j < g[i].size(); j++) {
			cout << g[i][j] + 1 << " ";
		}
		ln;
	}
	*/

	// cout << "before dfs\n";
	dfs(0);
	// cout << "after dfs\n";

	/*for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			ll w = lca(i, j);
			ll w1 = lca(j, i);
			cout << weigh_of_tree - max(w, w1) + cost[{i, j}] << endl;
		}
	}*/

	//cout << weigh_of_tree << endl;

	for (ll i = 0; i < m; i++) {
		ll w = lca(vec[i].first, vec[i].second);
		ll w1 = lca(vec[i].second, vec[i].first);
		cout << weigh_of_tree - max(w, w1) + cost[{vec[i].first, vec[i].second}] << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int nmax = 2 * 1e5;
#define ll int
#define pb push_back
#define all(X) sort(X.begin(), X.end())
#define ln cout << endl
ll n;

vector<pair<ll, ll> > v;
vector<pair<ll, ll> > vec;
vector<ll> parent(nmax, -1);
vector<vector<ll> > g;
vector<vector<ll> > mx(nmax, vector<ll> (20));
vector<vector<ll> > pr(nmax, vector<ll> (20));
vector<ll> tin(nmax);
vector<ll> tout(nmax);
ll timer = 0;
map<pair<ll, ll>, ll> cost;

int cmp (pair<int, int> a, pair<int, int> b) {
    auto x = cost[{a.first, a.second}];
    auto y = cost[{b.first, b.second}]
	if ( x!=y )
		return x<y;
	return a<b;
}

ll find (ll v) {
	if (parent[v] == v)
		return v;
	else
		return parent[v] = find(parent[v]);
}

ll unon (ll a, ll b) {
	a = find(a);
	b = find(b);
	if (a > b)
		swap(a, b);
	if (a == b)
    	return 0;
	if (rand()&1)
		parent[b] = a;
	else
	    parent[a] = b;
		return 1;

}

void dfs (ll v, ll p = 0) {
	tin[v] = timer++;
	pr[v][0] = p;
	if (cost.count({v, p}));
	mx[v][0] = cost[{v, p}];
	for (ll i = 1; i < 20; i++) {
		pr[v][i] = pr[pr[v][i - 1]][i - 1];
		mx[v][i] = max(mx[v][i - 1], mx[pr[v][i - 1]][i - 1]);
	}
	for (ll i = 0; i < g[v].size(); i++) {
		ll to = g[v][i];
		if (to == p)
			continue;
		dfs(to, v);
	}
	tout[v] = timer++;
}

ll upper (ll a, ll b) {
	if (tin[a] <= tin[b] && tout[a] >= tout[b])
		return 1;
	else
		return 0;
}

ll lca (ll a, ll b) {
	if (upper(a, b))
		return 0;
	ll ans = 0;
	for (ll i = 19; i >= 0; i--){
		if (!upper(pr[a][i], b)) {
			ans = max(ans, mx[a][i]);
			a = pr[a][i];
		}
	}
	ans = max(ans, mx[a][0]);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll m; cin >> n >> m;
	v.resize(m);
	g.resize(n);
	vec.resize(m);
	for (ll i = 0; i < m; i++) {
		ll q;
		cin >> v[i].first >> v[i].second >> q;
		if (v[i].first>v[i].second)
    		swap(v[i].first,v[i].second);
		v[i].first = v[i].first - 1;
		vec[i].first = v[i].first;
		v[i].second = v[i].second - 1;
		vec[i].second = v[i].second;
		cost[{v[i].first, v[i].second}] = q;
	}
	sort(v.begin(), v.end(), cmp);

	// cout << "OK\n";

	long long weigh_of_tree = 0;
	for (ll i = 0; i < m; i++) {
		if (parent[v[i].first] == -1)
			parent[v[i].first] = v[i].first;
		if (parent[v[i].second] == -1)
			parent[v[i].second] = v[i].second;
		if (unon(v[i].first, v[i].second) == 1) {
			//cout << v[i].first << " " << v[i].second << "\n";
			g[v[i].first].pb(v[i].second);
			g[v[i].second].pb(v[i].first);
			weigh_of_tree += cost[{v[i].first, v[i].second}];
		}
	}

	/*
	for (ll i = 0; i < n; i++) {
			cout << i + 1 << ":\n";
		for (ll j = 0; j < g[i].size(); j++) {
			cout << g[i][j] + 1 << " ";
		}
		ln;
	}
	*/

	// cout << "before dfs\n";
	dfs(0);
	// cout << "after dfs\n";

	/*for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			ll w = lca(i, j);
			ll w1 = lca(j, i);
			cout << weigh_of_tree - max(w, w1) + cost[{i, j}] << endl;
		}
	}*/

	//cout << weigh_of_tree << endl;

	for (ll i = 0; i < m; i++) {
		ll w = lca(vec[i].first, vec[i].second);
		ll w1 = lca(vec[i].second, vec[i].first);
		cout << weigh_of_tree - max(w, w1) + cost[{vec[i].first, vec[i].second}] << endl;
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iomanip>
#include <queue>
using namespace std;

void solve();
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}
#define int long long

const int MAXN = 2e5;
const int lg = 20;
int p[MAXN];
int get_set(int v)
{
    if (p[v] == v)
        return v;
    return p[v] = get_set(p[v]);
}
void union_set(int a, int b)
{
    a = get_set(a);
    b = get_set(b);
    if (rand()&1)
        p[a] = b;
    else
        p[b] = a;
}
int mx[MAXN][lg],lca[MAXN][lg];
vector<pair<int,int>> g[MAXN];
int tin[MAXN],tout[MAXN];
int timer;
void dfs(int v, int pr, int cost)
{
    tin[v] = timer++;
    lca[v][0] = pr;
    mx[v][0] = cost;
    for (int i = 1; i<lg; i++)
    {
        lca[v][i] = lca[lca[v][i-1]][i-1];
        mx[v][i] = max(mx[v][i-1],mx[lca[v][i-1]][i-1]);
    }
    for (auto to:g[v])
    {
        if (to.first!=pr)
        {
            dfs(to.first,v,to.second);
        }
    }
    tout[v] = timer++;
}

bool is_upper(int low, int up)
{
    return tin[up]<=tin[low] && tout[up]>=tout[low];
}
int find_lca(int u, int v)
{
    if (is_upper(u, v))
        return v;
    if (is_upper(v, u))
        return u;
    for (int i = lg-1; i>=0; i--)
        if (!is_upper(lca[u][i], v))
            u = lca[u][i];
    return lca[u][0];
}
int max_in_path(int a, int lc)
{
    if (a == lc)
        return 0;
    int ans = 0;
    for (int i = lg-1; i>=0; i--)
        if (!is_upper(lc, lca[a][i]))
        {
            ans = max(ans,mx[a][i]);
            a = lca[a][i];
        }
    ans = max(ans,mx[a][0]);
    return ans;
}
int query(int a, int b)
{
    int lc = find_lca(a,b);
    return max(max_in_path(a, lc),max_in_path(b, lc));

}
void solve()
{
    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<pair<pair<int,int>,pair<int,int>>> edges(m);
    for (int i = 0; i<m; i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        edges[i] = {{c,i},{a-1,b-1}};
    }
    for (int i = 0; i<n; i++)
        p[i] = i;

    sort(edges.begin(),edges.end());
    int ans = 0;
    for (int i = 0; i<m; i++)
    {
        int a= edges[i].second.first,b = edges[i].second.second;
        if (get_set(a)!=get_set(b))
        {
            ans+=edges[i].first.first;
            union_set(a, b);
            g[a].push_back({b,edges[i].first.first});
            g[b].push_back({a,edges[i].first.first});
        }
    }
    dfs(0,0,0);
    vector<int> res(m);
    for (int i = 0; i<m; i++)
    {
        int a = edges[i].second.first;
        int b = edges[i].second.second;
        int c = edges[i].first.first;
        int id = edges[i].first.second;
        int x = query(a, b);
        res[id] = ans - x + c;
    }
    for (auto it:res)
        cout << it << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <string>
#include <set>
#include <random>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <thread>
#include <atomic>
#include <mutex>

using namespace std;

const int nmax = 2 * 1e5;
#define ll int
#define pb push_back
#define all(X) sort(X.begin(), X.end())
#define ln cout << endl
ll n;

vector<pair<ll, ll> > v;
vector<pair<ll, ll> > vec;
vector<ll> parent(nmax, -1);
vector<vector<ll> > g;
vector<vector<ll> > mx(nmax, vector<ll> (20));
vector<vector<ll> > pr(nmax, vector<ll> (20));
vector<ll> tin(nmax);
vector<ll> tout(nmax);
ll timer = 0;
map<pair<ll, ll>, ll> cost;

int cmp (pair<int, int> a, pair<int, int> b) {
    auto x = cost[{a.first, a.second}];
    auto y = cost[{b.first, b.second}];
    if ( x!=y )
        return x<y;
    return a<b;
}

ll find (ll v) {
    if (parent[v] == v)
        return v;
    else
        return parent[v] = find(parent[v]);
}

ll unon (ll a, ll b) {
    a = find(a);
    b = find(b);
    if (a > b)
        swap(a, b);
    if (a == b)
        return 0;
    if (rand()&1)
        parent[b] = a;
    else
        parent[a] = b;
    return 1;

}

void dfs (ll v, ll p = 0) {
    tin[v] = timer++;
    pr[v][0] = p;
    if (cost.count({v, p}));
    mx[v][0] = cost[{v, p}];
    for (ll i = 1; i < 20; i++) {
        pr[v][i] = pr[pr[v][i - 1]][i - 1];
        mx[v][i] = max(mx[v][i - 1], mx[pr[v][i - 1]][i - 1]);
    }
    for (ll i = 0; i < g[v].size(); i++) {
        ll to = g[v][i];
        if (to == p)
            continue;
        dfs(to, v);
    }
    tout[v] = timer++;
}

ll upper (ll a, ll b) {
    if (tin[a] <= tin[b] && tout[a] >= tout[b])
        return 1;
    else
        return 0;
}

ll lca (ll a, ll b) {
    if (upper(a, b))
        return 0;
    ll ans = 0;
    for (ll i = 19; i >= 0; i--){
        if (!upper(pr[a][i], b)) {
            ans = max(ans, mx[a][i]);
            a = pr[a][i];
        }
    }
    ans = max(ans, mx[a][0]);
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll m; cin >> n >> m;
    v.resize(m);
    g.resize(n);
    vec.resize(m);
    for (ll i = 0; i < m; i++) {
        ll q;
        cin >> v[i].first >> v[i].second >> q;
        if (v[i].first>v[i].second)
            swap(v[i].first,v[i].second);
        v[i].first = v[i].first - 1;
        vec[i].first = v[i].first;
        v[i].second = v[i].second - 1;
        vec[i].second = v[i].second;
        cost[{v[i].first, v[i].second}] = q;
        cost[{v[i].second, v[i].first}] = q;
    }
    sort(v.begin(), v.end(), cmp);

    // cout << "OK\n";

    long long weigh_of_tree = 0;
    for (ll i = 0; i < m; i++) {
        if (parent[v[i].first] == -1)
            parent[v[i].first] = v[i].first;
        if (parent[v[i].second] == -1)
            parent[v[i].second] = v[i].second;
        if (unon(v[i].first, v[i].second) == 1) {
            //cout << v[i].first << " " << v[i].second << "\n";
            g[v[i].first].pb(v[i].second);
            g[v[i].second].pb(v[i].first);
            weigh_of_tree += cost[{v[i].first, v[i].second}];
        }
    }

    /*
    for (ll i = 0; i < n; i++) {
            cout << i + 1 << ":\n";
        for (ll j = 0; j < g[i].size(); j++) {
            cout << g[i][j] + 1 << " ";
        }
        ln;
    }
    */

    // cout << "before dfs\n";
    dfs(0);
    // cout << "after dfs\n";

    /*for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            ll w = lca(i, j);
            ll w1 = lca(j, i);
            cout << weigh_of_tree - max(w, w1) + cost[{i, j}] << endl;
        }
    }*/

    //cout << weigh_of_tree << endl;

    for (ll i = 0; i < m; i++) {
        ll w = lca(vec[i].first, vec[i].second);
        ll w1 = lca(vec[i].second, vec[i].first);
        cout << weigh_of_tree - max(w, w1) + cost[{vec[i].first, vec[i].second}] << endl;
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iomanip>
#include <queue>
using namespace std;

void solve();
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}
#define int long long

const int MAXN = 2e5;
const int lg = 20;
int p[MAXN];
int get_set(int v)
{
    if (p[v] == v)
        return v;
    return p[v] = get_set(p[v]);
}
void union_set(int a, int b)
{
    a = get_set(a);
    b = get_set(b);
    if (rand()&1)
        p[a] = b;
    else
        p[b] = a;
}
int mx[MAXN][lg],lca[MAXN][lg];
vector<pair<int,int>> g[MAXN];
int tin[MAXN],tout[MAXN];
int timer;
void dfs(int v, int pr, int cost)
{
    tin[v] = timer++;
    lca[v][0] = pr;
    mx[v][0] = cost;
    for (int i = 1; i<lg; i++)
    {
        lca[v][i] = lca[lca[v][i-1]][i-1];
        mx[v][i] = max(mx[v][i-1],mx[lca[v][i-1]][i-1]);
    }
    for (auto to:g[v])
    {
        if (to.first!=pr)
        {
            dfs(to.first,v,to.second);
        }
    }
    tout[v] = timer++;
}

bool is_upper(int low, int up)
{
    return tin[up]<=tin[low] && tout[up]>=tout[low];
}
int find_lca(int u, int v)
{
    if (is_upper(u, v))
        return v;
    if (is_upper(v, u))
        return u;
    for (int i = lg-1; i>=0; i--)
        if (!is_upper(v,lca[u][i]))
            u = lca[u][i];
    return lca[u][0];
}
int max_in_path(int a, int lc)
{
    if (a == lc)
        return 0;
    int ans = 0;
    for (int i = lg-1; i>=0; i--)
        if (!is_upper(lc, lca[a][i]))
        {
            ans = max(ans,mx[a][i]);
            a = lca[a][i];
        }
    ans = max(ans,mx[a][0]);
    return ans;
}
int query(int a, int b)
{
    int lc = find_lca(a,b);
    return max(max_in_path(a, lc),max_in_path(b, lc));

}
void solve()
{
    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<pair<pair<int,int>,pair<int,int>>> edges(m);
    for (int i = 0; i<m; i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        edges[i] = {{c,i},{a-1,b-1}};
    }
    for (int i = 0; i<n; i++)
        p[i] = i;

    sort(edges.begin(),edges.end());
    int ans = 0;
    for (int i = 0; i<m; i++)
    {
        int a= edges[i].second.first,b = edges[i].second.second;
        if (get_set(a)!=get_set(b))
        {
            ans+=edges[i].first.first;
            union_set(a, b);
            g[a].push_back({b,edges[i].first.first});
            g[b].push_back({a,edges[i].first.first});
        }
    }

    dfs(0,0,0);
    vector<int> res(m);
    for (int i = 0; i<m; i++)
    {
        int a = edges[i].second.first;
        int b = edges[i].second.second;
        int c = edges[i].first.first;
        int id = edges[i].first.second;
        if (id == 3)
            id = 3;
        int x = query(a, b);

        res[id] = ans - x + c;
    }
    for (auto it:res)
        cout << it << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int nmax = 2 * 1e5;
#define ll int
#define pb push_back
#define all(X) sort(X.begin(), X.end())
#define ln cout << endl
ll n;

vector<pair<ll, ll> > v;
vector<pair<ll, ll> > vec;
vector<ll> parent(nmax, -1);
vector<vector<ll> > g;
vector<vector<ll> > mx(nmax, vector<ll> (20));
vector<vector<ll> > pr(nmax, vector<ll> (20));
vector<ll> tin(nmax);
vector<ll> tout(nmax);
ll timer = 0;
map<pair<ll, ll>, ll> cost;

int cmp (pair<int, int> a, pair<int, int> b) {
    auto x = cost[{a.first, a.second}];
    auto y = cost[{b.first, b.second}];
	if ( x!=y )
		return x<y;
	return a<b;
}

ll find (ll v) {
	if (parent[v] == v)
		return v;
	else
		return parent[v] = find(parent[v]);
}

ll unon (ll a, ll b) {
	a = find(a);
	b = find(b);
	if (a > b)
		swap(a, b);
	if (a == b)
    	return 0;
	if (rand()&1)
		parent[b] = a;
	else
	    parent[a] = b;
		return 1;

}

void dfs (ll v, ll p = 0) {
	tin[v] = timer++;
	pr[v][0] = p;
	if (cost.count({v, p}));
	mx[v][0] = cost[{v, p}];
	for (ll i = 1; i < 20; i++) {
		pr[v][i] = pr[pr[v][i - 1]][i - 1];
		mx[v][i] = max(mx[v][i - 1], mx[pr[v][i - 1]][i - 1]);
	}
	for (ll i = 0; i < g[v].size(); i++) {
		ll to = g[v][i];
		if (to == p)
			continue;
		dfs(to, v);
	}
	tout[v] = timer++;
}

ll upper (ll a, ll b) {
	if (tin[a] <= tin[b] && tout[a] >= tout[b])
		return 1;
	else
		return 0;
}

ll lca (ll a, ll b) {
	if (upper(a, b))
		return 0;
	ll ans = 0;
	for (ll i = 19; i >= 0; i--){
		if (!upper(pr[a][i], b)) {
			ans = max(ans, mx[a][i]);
			a = pr[a][i];
		}
	}
	ans = max(ans, mx[a][0]);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll m; cin >> n >> m;
	v.resize(m);
	g.resize(n);
	vec.resize(m);
	for (ll i = 0; i < m; i++) {
		ll q;
		cin >> v[i].first >> v[i].second >> q;
		if (v[i].first>v[i].second)
    		swap(v[i].first,v[i].second);
		v[i].first = v[i].first - 1;
		vec[i].first = v[i].first;
		v[i].second = v[i].second - 1;
		vec[i].second = v[i].second;
		cost[{v[i].first, v[i].second}] = q;
	}
	sort(v.begin(), v.end(), cmp);

	// cout << "OK\n";

	long long weigh_of_tree = 0;
	for (ll i = 0; i < m; i++) {
		if (parent[v[i].first] == -1)
			parent[v[i].first] = v[i].first;
		if (parent[v[i].second] == -1)
			parent[v[i].second] = v[i].second;
		if (unon(v[i].first, v[i].second) == 1) {
			//cout << v[i].first << " " << v[i].second << "\n";
			g[v[i].first].pb(v[i].second);
			g[v[i].second].pb(v[i].first);
			weigh_of_tree += cost[{v[i].first, v[i].second}];
		}
	}

	/*
	for (ll i = 0; i < n; i++) {
			cout << i + 1 << ":\n";
		for (ll j = 0; j < g[i].size(); j++) {
			cout << g[i][j] + 1 << " ";
		}
		ln;
	}
	*/

	// cout << "before dfs\n";
	dfs(0);
	// cout << "after dfs\n";

	/*for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			ll w = lca(i, j);
			ll w1 = lca(j, i);
			cout << weigh_of_tree - max(w, w1) + cost[{i, j}] << endl;
		}
	}*/

	//cout << weigh_of_tree << endl;

	for (ll i = 0; i < m; i++) {
		ll w = lca(vec[i].first, vec[i].second);
		ll w1 = lca(vec[i].second, vec[i].first);
		cout << weigh_of_tree - max(w, w1) + cost[{vec[i].first, vec[i].second}] << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int nmax = 2 * 1e5;
#define ll int
#define pb push_back
#define all(X) sort(X.begin(), X.end())
#define ln cout << endl
ll n;

vector<pair<ll, ll> > v;
vector<pair<ll, ll> > vec;
vector<ll> parent(nmax, -1);
vector<vector<ll> > g;
vector<vector<ll> > mx(nmax, vector<ll> (20));
vector<vector<ll> > pr(nmax, vector<ll> (20));
vector<ll> tin(nmax);
vector<ll> tout(nmax);
ll timer = 0;
map<pair<ll, ll>, ll> cost;

int cmp (pair<int, int> a, pair<int, int> b) {
	if (cost[{a.first, a.second}] < cost[{b.first, b.second}])
		return 1;
	return 0;
}

ll find (ll v) {
	if (parent[v] == v)
		return v;
	else
		return parent[v] = find(parent[v]);
}

ll unon (ll a, ll b) {
	a = find(a);
	b = find(b);
	if (a > b)
		swap(a, b);
	if (a == b)
    	return 0;
	if (rand()&1)
		parent[b] = a;
	else
	    parent[a] = b;
		return 1;

}

void dfs (ll v, ll p = 0) {
	tin[v] = timer++;
	pr[v][0] = p;
	if (cost.count({v, p}));
	mx[v][0] = cost[{v, p}];
	for (ll i = 1; i < 20; i++) {
		pr[v][i] = pr[pr[v][i - 1]][i - 1];
		mx[v][i] = max(mx[v][i - 1], mx[pr[v][i - 1]][i - 1]);
	}
	for (ll i = 0; i < g[v].size(); i++) {
		ll to = g[v][i];
		if (to == p)
			continue;
		dfs(to, v);
	}
	tout[v] = timer++;
}

ll upper (ll a, ll b) {
	if (tin[a] <= tin[b] && tout[a] >= tout[b])
		return 1;
	else
		return 0;
}

ll lca (ll a, ll b) {
	if (upper(a, b))
		return 0;
	ll ans = 0;
	for (ll i = 19; i >= 0; i--){
		if (!upper(pr[a][i], b)) {
			ans = max(ans, mx[a][i]);
			a = pr[a][i];
		}
	}
	ans = max(ans, mx[a][0]);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll m; cin >> n >> m;
	v.resize(m);
	g.resize(n);
	vec.resize(m);
	for (ll i = 0; i < m; i++) {
		ll q;
		cin >> v[i].first >> v[i].second >> q;
		if (v[i].first>v[i].second)
    		swap(v[i].first,v[i].second);
		v[i].first = v[i].first - 1;
		vec[i].first = v[i].first;
		v[i].second = v[i].second - 1;
		vec[i].second = v[i].second;
		cost[{v[i].first, v[i].second}] = q;
	}
	sort(v.begin(), v.end(), cmp);

	// cout << "OK\n";

	long long weigh_of_tree = 0;
	for (ll i = 0; i < m; i++) {
		if (parent[v[i].first] == -1)
			parent[v[i].first] = v[i].first;
		if (parent[v[i].second] == -1)
			parent[v[i].second] = v[i].second;
		if (unon(v[i].first, v[i].second) == 1) {
			//cout << v[i].first << " " << v[i].second << "\n";
			g[v[i].first].pb(v[i].second);
			g[v[i].second].pb(v[i].first);
			weigh_of_tree += cost[{v[i].first, v[i].second}];
		}
	}

	/*
	for (ll i = 0; i < n; i++) {
			cout << i + 1 << ":\n";
		for (ll j = 0; j < g[i].size(); j++) {
			cout << g[i][j] + 1 << " ";
		}
		ln;
	}
	*/

	// cout << "before dfs\n";
	dfs(0);
	// cout << "after dfs\n";

	/*for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			ll w = lca(i, j);
			ll w1 = lca(j, i);
			cout << weigh_of_tree - max(w, w1) + cost[{i, j}] << endl;
		}
	}*/

	//cout << weigh_of_tree << endl;

	for (ll i = 0; i < m; i++) {
		ll w = lca(vec[i].first, vec[i].second);

		cout << weigh_of_tree - w + cost[{vec[i].first, vec[i].second}] << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int nmax = 2 * 1e5;
#define ll int
#define pb push_back
#define all(X) sort(X.begin(), X.end())
#define ln cout << endl
ll n;

vector<pair<ll, ll> > v;
vector<pair<ll, ll> > vec;
vector<ll> parent(nmax, -1);
vector<vector<ll> > g;
vector<vector<ll> > mx(nmax, vector<ll> (20));
vector<vector<ll> > pr(nmax, vector<ll> (20));
vector<ll> tin(nmax);
vector<ll> tout(nmax);
ll timer = 0;
map<pair<ll, ll>, ll> cost;

int cmp (pair<int, int> a, pair<int, int> b) {
auto x = cost[{a.first, a.second}];
    auto y = cost[{b.first, b.second}];
    if ( x!=y )
        return x<y;
    return a<b;
}

ll find (ll v) {
	if (parent[v] == v)
		return v;
	else
		return parent[v] = find(parent[v]);
}

ll unon (ll a, ll b) {
	a = find(a);
	b = find(b);
	if (a > b)
		swap(a, b);
	if (a == b)
    	return 0;
	if (rand()&1)
		parent[b] = a;
	else
	    parent[a] = b;
		return 1;

}

void dfs (ll v, ll p = 0) {
	tin[v] = timer++;
	pr[v][0] = p;
	if (cost.count({v, p}));
	mx[v][0] = cost[{v, p}];
	for (ll i = 1; i < 20; i++) {
		pr[v][i] = pr[pr[v][i - 1]][i - 1];
		mx[v][i] = max(mx[v][i - 1], mx[pr[v][i - 1]][i - 1]);
	}
	for (ll i = 0; i < g[v].size(); i++) {
		ll to = g[v][i];
		if (to == p)
			continue;
		dfs(to, v);
	}
	tout[v] = timer++;
}

ll upper (ll a, ll b) {
	if (tin[a] <= tin[b] && tout[a] >= tout[b])
		return 1;
	else
		return 0;
}

ll lca (ll a, ll b) {
	if (upper(a, b))
		return 0;
	ll ans = 0;
	for (ll i = 19; i >= 0; i--){
		if (!upper(pr[a][i], b)) {
			ans = max(ans, mx[a][i]);
			a = pr[a][i];
		}
	}
	ans = max(ans, mx[a][0]);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll m; cin >> n >> m;
	v.resize(m);
	g.resize(n);
	vec.resize(m);
	for (ll i = 0; i < m; i++) {
		ll q;
		cin >> v[i].first >> v[i].second >> q;
		v[i].first = v[i].first - 1;
		vec[i].first = v[i].first;
		v[i].second = v[i].second - 1;
		vec[i].second = v[i].second;
		cost[{v[i].first, v[i].second}] = q;
		cost[{v[i].second, v[i].first}] = q;
	}
	sort(v.begin(), v.end(), cmp);

	// cout << "OK\n";

	long long weigh_of_tree = 0;
	for (ll i = 0; i < m; i++) {
		if (parent[v[i].first] == -1)
			parent[v[i].first] = v[i].first;
		if (parent[v[i].second] == -1)
			parent[v[i].second] = v[i].second;
		if (unon(v[i].first, v[i].second) == 1) {
			//cout << v[i].first << " " << v[i].second << "\n";
			g[v[i].first].pb(v[i].second);
			g[v[i].second].pb(v[i].first);
			weigh_of_tree += cost[{v[i].first, v[i].second}];
		}
	}

	/*
	for (ll i = 0; i < n; i++) {
			cout << i + 1 << ":\n";
		for (ll j = 0; j < g[i].size(); j++) {
			cout << g[i][j] + 1 << " ";
		}
		ln;
	}
	*/

	// cout << "before dfs\n";
	dfs(0);
	// cout << "after dfs\n";

	/*for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			ll w = lca(i, j);
			ll w1 = lca(j, i);
			cout << weigh_of_tree - max(w, w1) + cost[{i, j}] << endl;
		}
	}*/

	//cout << weigh_of_tree << endl;

	for (ll i = 0; i < m; i++) {
		ll w = lca(vec[i].first, vec[i].second);
		ll w1 = lca(vec[i].second, vec[i].first);
		cout << weigh_of_tree - max(w, w1) + cost[{vec[i].first, vec[i].second}] << endl;
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iomanip>
#include <queue>
using namespace std;

#define int long long

void solve();
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}

const int MAXN = 2e5;
const int lg = 20;
int p[MAXN];
int get_set(int v)
{
    if (p[v] == v)
        return v;
    return p[v] = get_set(p[v]);
}
void union_set(int a, int b)
{
    a = get_set(a);
    b = get_set(b);
    if (rand()&1)
        p[a] = b;
    else
        p[b] = a;
}
int mx[MAXN][lg],lca[MAXN][lg];
vector<pair<int,int>> g[MAXN];
int tin[MAXN],tout[MAXN];
int timer;
void dfs(int v, int pr, int cost)
{
    tin[v] = timer++;
    lca[v][0] = pr;
    mx[v][0] = cost;
    for (int i = 1; i<lg; i++)
    {
        lca[v][i] = lca[lca[v][i-1]][i-1];
        mx[v][i] = max(mx[v][i-1],mx[lca[v][i-1]][i-1]);
    }
    for (auto to:g[v])
    {
        if (to.first!=pr)
        {
            dfs(to.first,v,to.second);
        }
    }
    tout[v] = timer++;
}

bool is_upper(int low, int up)
{
    return tin[up]<=tin[low] && tout[up]>=tout[low];
}
int find_lca(int u, int v)
{
    if (is_upper(u, v))
        return v;
    if (is_upper(v, u))
        return u;
    for (int i = lg-1; i>=0; i--)
        if (!is_upper(u, v))
            u = lca[u][i];
    return lca[u][0];
}
int max_in_path(int a, int lc)
{
    int ans = 0;
    for (int i = lg-1; i>=0; i--)
        if (!is_upper(lc, a))
        {
            ans = max(ans,mx[a][i]);
            a = lca[a][i];
        }
    ans = max(ans,mx[a][0]);
    return ans;
}
int query(int a, int b)
{
    int lc = find_lca(a,b);
    return max(max_in_path(a, lc),max_in_path(b, lc));

}
void solve()
{
    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<pair<pair<int,int>,pair<int,int>>> edges(m);
    for (int i = 0; i<m; i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        edges[i] = {{c,i},{a-1,b-1}};
    }
    for (int i = 0; i<n; i++)
        p[i] = i;

    sort(edges.begin(),edges.end());
    int ans = 0;
    for (int i = 0; i<m; i++)
    {
        int a= edges[i].second.first,b = edges[i].second.second;
        if (get_set(a)!=get_set(b))
        {
            ans+=edges[i].first.first;
            union_set(a, b);
            g[a].push_back({b,edges[i].first.first});
            g[b].push_back({a,edges[i].first.first});
        }
    }
    dfs(0,0,0);
    vector<int> res(m);
    for (int i = 0; i<m; i++)
    {
        int a = edges[i].second.first;
        int b = edges[i].second.second;
        int c = edges[i].first.first;
        int id = edges[i].first.second;
        int x = query(a, b);
        res[id] = ans - x + c;
    }
    for (auto it:res)
        cout << it << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int u, int v){
    int lev_of_u = level[u], lev_of_v = level[v];
    //if(level[u] == level[v]) return u;
    //cout<<u<<"  "<<lev_of_u<<"   v = "<<level[v]<<'\n';
    if(level[u] > level[v]){
        swap(lev_of_u, lev_of_v); ///lev_of_u <= lev_of_v    assume kore nichi
        swap(u, v);
    }
    int node = v; /// v k upore tulte hobe
    while(1){
        if(level[u] == level[v]) break;
        for(int k = 1; k < MX; k++){
            node = parSP[v][k];
            if(level[u] == level[node]) {
                v = node;
                break;
            }
            if(level[node] < level[u]) {
                v = parSP[v][k-1];
                break;
            }
        }
    }
    //cout<<"level = "<<level[u]<<"   "<<level[v]<<'\n';
    int nod1 = u, nod2 = v;
    while(1){
        if(u == v) return u;
        if(parSP[u][1] == parSP[v][1]) return parSP[u][1];
        for(int k = 1; k < MX; k++){
            nod1 = parSP[u][k];
            nod2 = parSP[v][k];
           // cout<<"nod1 = "<<nod1<<"  nod2 = "<<nod2<<'\n';
            if(nod1 == nod2) {
                u = parSP[u][k-1];
                v = parSP[v][k-1];
                break;
            }
        }
    }
}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int szzz = edges.size();
    int root = get<1>(edges[szzz/2].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<=level[q]) swap(p,q);
    int log=log2(level[p]);

    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int k = 1; k < MX; k++){
        for(int i = 1; i <= n; i++) parSP[i][k] = -1;
    }
    for(int i = 1; i <= n; i++) parSP[i][0] = par[i];
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            if(parSP[j][k-1] != -1)
                parSP[j][k] = parSP[parSP[j][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<level[q]) swap(p,q);
    int log;
    for(log = 1; 1<<log <= level[p]; log++);
    log--;
    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i] != -1 && parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX    18
#define  mm    10000

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<=level[q]) swap(p,q);
    int log=log2(level[p]);

    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][20], parSP[LIM+5][20];
int dsuPar[LIM+5], sz[LIM+5];
map<pii, int> cost;
LL mst;

void dfs(int u, int prev = -1){
    for(int v : adj[u]){
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < 20; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < 20; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < 20; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int u, int v){
    int lev_of_u = level[u], lev_of_v = level[v];
    //if(level[u] == level[v]) return u;
    if(level[u] > level[v]){
        swap(lev_of_u, lev_of_v); ///lev_of_u <= lev_of_v    assume kore nichi
        swap(u, v);
    }
    int node = v; /// v k upore tulte hobe
    while(1){
        if(level[u] == level[v]) break;
        for(int k = 1; k < 20; k++){
            node = parSP[v][k];
            if(level[u] == level[node]) {
                v = node;
                break;
            }
            if(level[node] < level[u]) {
                v = parSP[v][k-1];
                break;
            }
        }
    }
    //cout<<"level = "<<level[u]<<"   "<<level[v]<<'\n';
    int nod1 = u, nod2 = v;
    while(1){
        if(u == v) return u;
        if(parSP[u][1] == parSP[v][1]) return parSP[u][1];
        for(int k = 0; k < 20; k++){
            nod1 = parSP[u][k];
            nod2 = parSP[v][k];
           // cout<<"nod1 = "<<nod1<<"  nod2 = "<<nod2<<'\n';
            if(nod1 == nod2) {
                u = parSP[u][k-1];
                v = parSP[v][k-1];
                break;
            }
        }
    }
}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < 20; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return findPar(dsuPar[u]);
}

void unite(int d, int u, int v){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(p1 == u){
        dsuPar[p1] = v;
        sz[p2] += sz[p1];
    }
    else{
        dsuPar[p2] = u;
        sz[p1] += sz[p2];
    }

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; cin>>n>>e;
    if(n == 1) return 0;
    vector<tpl> edges;

    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;

        edges.push_back(make_tuple(len, u, v));
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpl> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[edges.size()/2]);
    for(tpl it : edges){
        int d = get<0>(it);
        int u = get<1>(it);
        int v = get<2>(it);
        unite(d, u, v);
    }
    dfs(root);
    createParSP();
    createSP();

    int query = e;
    for(tpl it : tmp){
        int u = get<1>(it);
        int v = get<2>(it);
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        cout<<(mst - mx + get<0>(it))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][18], parSP[LIM+5][18];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;

void dfs(int u, int prev = -1){
    for(int v : adj[u]){
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < 18; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < 18; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < 18; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int u, int v){
    int lev_of_u = level[u], lev_of_v = level[v];
    //if(level[u] == level[v]) return u;
    if(level[u] > level[v]){
        swap(lev_of_u, lev_of_v); ///lev_of_u <= lev_of_v    assume kore nichi
        swap(u, v);
    }
    int node = v; /// v k upore tulte hobe
    while(1){
        if(level[u] == level[v]) break;
        for(int k = 1; k < 18; k++){
            node = parSP[v][k];
            if(level[u] == level[node]) {
                v = node;
                break;
            }
            if(level[node] < level[u]) {
                v = parSP[v][k-1];
                break;
            }
        }
    }
    //cout<<"level = "<<level[u]<<"   "<<level[v]<<'\n';
    int nod1 = u, nod2 = v;
    while(1){
        if(u == v) return u;
        if(parSP[u][1] == parSP[v][1]) return parSP[u][1];
        for(int k = 0; k < 18; k++){
            nod1 = parSP[u][k];
            nod2 = parSP[v][k];
           // cout<<"nod1 = "<<nod1<<"  nod2 = "<<nod2<<'\n';
            if(nod1 == nod2) {
                u = parSP[u][k-1];
                v = parSP[v][k-1];
                break;
            }
        }
    }
}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < 18; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(p1 == u){
        dsuPar[p1] = v;
        sz[p2] += sz[p1];
    }
    else{
        dsuPar[p2] = u;
        sz[p1] += sz[p2];
    }

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;

    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[edges.size()/2].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    int query = e;
    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int k = 1; k < MX; k++){
        for(int i = 1; i <= n; i++) parSP[i][k] = -1;
    }
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            if(parSP[j][k-1] != -1)
                parSP[j][k] = parSP[parSP[j][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<level[q]) swap(p,q);
    int log;
    for(log = 1; 1<<log <= level[p]; log++);
    log--;
    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i] != -1 && parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<level[q]) swap(p,q);
    int log;
    for(log = 1; 1<<log <= level[p]; log++);
    log--;
    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return parSP[p][0];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<level[q]) swap(p,q);
    int log;
    for(log = 1; 1<<log <= level[p]; log++);
    log--;
    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<level[q]) swap(p,q);
    int log;
    for(log = 1; 1<<log <= level[p]; log++);
    log--;
    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p][0];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];

void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = par[i];
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<=level[q]) swap(p,q);
    int log=log2(level[p]);

    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define  LL    long long int
#define  pii   pair<int, int>
#define  tpi   pair<tpl, int>
#define  pb    push_back
#define  ff    first
#define  ss    second
#define  LIM   200000
#define  tpl   tuple<int, int, int>
#define  MX 18

vector<int> adj[LIM+5];
int n, root, level[LIM+5], par[LIM+5], maxSP[LIM+5][MX], parSP[LIM+5][MX];
int dsuPar[LIM+5], sz[LIM+5], mark[LIM+5];
map<pii, int> cost;
LL mst;
bool vis[LIM+5];
bool flag;
void dfs(int u, int prev = -1){
    vis[u] = 1;
    for(int v : adj[u]){
        if(vis[v]) continue;
        if(v == prev) continue;
        level[v] = level[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

void createParSP(){
    for(int i = 1; i <= n; i++) parSP[i][0] = i;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            parSP[j][k] = parSP[parSP[par[j]][k-1]][k-1];

        }
    }
}

void createSP(){
    for(int i = 1; i <= n; i++) {
        maxSP[i][0] = cost[{i, par[i]}];
    }
    //for(int i = 1; i <= n; i++) cout<<i<<"  "<<minSP[i][0]<<'\n';
    //return;
    for(int k = 1; k < MX; k++){
        for(int j = 1; j <= n; j++){
            maxSP[j][k] = max(maxSP[j][k-1], maxSP[par[parSP[j][k-1]]][k-1]);
        }
    }
    for(int i = 0; i < MX; i++){
        maxSP[root][i] = 0;
    }
}

int findLCA(int p, int q)
{
    if(level[p]<=level[q]) swap(p,q);
    int log=log2(level[p]);

    for(int i=log;i>=0;i--)
    {
        if(level[p]-(1<<i)>=level[q])
            p=parSP[p][i];
    }

    if(p==q) return p;

    for(int i=log;i>=0;i--)
    {
        if(parSP[p][i]!=parSP[q][i])
        {
            p=parSP[p][i];
            q=parSP[q][i];
        }
    }

    return par[p];

}

int findMax(int u, int lca){
    int node = u, lev = level[lca], mx = 0;
    int range = level[u] - lev;
    while(1){
        if(range <= 0) break;
        int cur = 0;
        for(int k = 0; k < MX; k++){
            if((1<<k) > range) break;
            cur = k;
        }
        range = range - (1<<cur);
        mx = max(mx, maxSP[u][cur]);
        u = par[parSP[u][cur]];
    }
    return mx;
}

int findPar(int u){
    if(dsuPar[u] == u) return u;
    return dsuPar[u] = findPar(dsuPar[u]);
}

void unite(int d, int u, int v, int pos){
    int p1 = findPar(u);
    int p2 = findPar(v);
    if(p1 == p2) return;
    if(sz[p1] < sz[p2]) swap(p1, p2);
    dsuPar[p2] = p1;
    sz[p1] += sz[p2];

    mst += (1LL*d);
    //cout<<p1<<" "<<u<<"   "<<p2<<" "<<v<<"        "<<mst<<'\n';
    mark[pos] = 1;
    adj[u].push_back(v);
    if(u != root) adj[v].push_back(u);

}

int main(){
    //freopen("ip.txt", "r", stdin);
    int e; scanf("%d %d", &n, &e);
    if(n == 1) return 0;
    vector<tpi> edges;
    LL sum = 0;
    for(int i = 0; i < e; i++){
        int u, v, len; scanf("%d %d %d", &u, &v, &len);
        cost[{u, v}] = len;
        cost[{v, u}] = len;
        sum += len;

        edges.push_back({make_tuple(len, u, v), i});
    }
    for(int i = 0; i <= n; i++) {
        par[i] = dsuPar[i] = i;
        sz[i] = 1;
    }
    vector<tpi> tmp;
    tmp = edges;
    sort(edges.begin(), edges.end());
    int root = get<1>(edges[0].ff);
    for(tpi it : edges){
        int d = get<0>(it.ff);
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        unite(d, u, v, it.ss);
    }
    dfs(root);
    createParSP();
    createSP();

    for(tpi it : tmp){
        if(mark[it.ss]){
            printf("%lld\n", mst);
            continue;
        }
        int u = get<1>(it.ff);
        int v = get<2>(it.ff);
        //cout<<"u = "<<u<<"  v = "<<v<<'\n';
        int lca = findLCA(u, v);
        //cout<<"lca = "<<lca<<"  u = "<<u<<"   v = "<<v<<'\n';
        int mx = findMax(u, lca); /// u theke lca te max
        //cout<<"mx1 = "<<mx;
        mx = max(mx, findMax(v, lca));
        //cout<<"   mx2 = "<<mx<<'\n';
        //cout<<maxSP[1][0];
        //break;
        printf("%lld\n", mst - (1LL*mx) + (1LL*get<0>(it.ff)))<<'\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

const ll maxn =10e5+10;
const ld SADAT = 7.84e-17;
const ll INF = 1e9;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>bool checkmin(T &a,T b){return a > b ? a = b, 1 : 0;}
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}
struct edge{
    int t  , next;
    ll w;
}e[maxn];
int n, l , m , g[maxn];
vector<int> adj[maxn];
int timer;
vector<int> tin, tout;
vector<vector<int> > up;
bool inmst[maxn];
int par[maxn];
ll ans[maxn];
int depth[maxn] , son[maxn][20] , dad[maxn][20];
int cnt ;
struct yall{
        int x , y, mark , k , w;
}yal[maxn];

bool cmp(yall i , yall j){
    return(i.w < j.w);
}

void dfs2(int v){
    for(int i=1;i<20;i++){
        dad[v][i]=dad[dad[v][i-1]][i-1];
        son[v][i]=max(son[dad[v][i-1]][i-1],son[v][i-1]);
    }
    for(int i=g[v];i;i=e[i].next){
        if(!depth[e[i].t]){
            depth[e[i].t]=depth[v]+1;
            dad[e[i].t][0]=v;
            son[e[i].t][0]=e[i].w;
            dfs2(e[i].t);
        }
    }
}

void add(int x,int y,int z){
    e[++cnt].t=y;
    e[cnt].w=z;
    e[cnt].next=g[x];
    g[x]=cnt;
}

int getpar(int v){
    if(par[v] == v){
        return(v);
    }
    par[v] = getpar(par[v]);
    return(par[v]);
}

void dfs(int v, int p){
    tin[v] = ++timer;
    //cout << v;
    up[v][0] = p;
    for (int i = 1; i <= l; ++i){
        up[v][i] = up[up[v][i-1]][i-1];
        //cout << l << '\t';
    }
    for (int i = 0 ; i < adj[v].size() ; i ++) {
        int u = adj[v][i];
        if(v == 3){
            //cout << u;
        }
        if (u!=p){
            dfs(u, v);
        }
    }
    //cout << v;
    tout[v] = ++timer;
    //cout << v;
}

bool is_ancestor(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

bool cmp2(yall i , yall j){
    return(i.k < j . k );
}

int lca(int u, int v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = l; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}

void preprocess(int root) {
    tin.resize(n);
    tout.resize(n);
    timer = 0;
    l = ceil(log2(n));
    up.assign(n, vector<int>(l + 1));
    dfs(root, root);

    //cout << 2;s
}

int pht(int x,int y){
    int h=depth[x]-depth[y],mx=0;
    for(int i = 0 ; h ; i ++){
        if(h & 1){
            mx=max(mx,son[x][i]);
            x=dad[x][i];
        }
        h>>=1;
    }
    return mx;
}

int main(){
    migmig
    cin >> n >> m;
    for (int i = 1 ;i <= m; i ++){
        int x , y , w;
        cin >> x >> y >> w;
        yal[i].x = x , yal[i].y = y , yal[i].k = i , yal[i].w = w;
    }
    sort(yal + 1 , yal + m + 1, cmp);
    for (int i =1 ; i <= n ; i ++){
        par[i ] = i ;
    }
    for (int i = 1 ; i <= m ; i ++){
        if(getpar(yal[i].x) != getpar(yal[i].y)){
            yal[i].mark = 1;
            int x = yal[i].x , y = yal[i].y;
            adj[x].pb(y);
            //cout << 2;
            adj[y].pb(x);
            //cout << 2;
            par[par[yal[i].x]] = par[yal[i].y];
            add(yal[i].x , yal[i].y , yal[i].w);
            add(yal[i].y , yal[i].x , yal[i].w);
        }
    }
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        if(yal[i].mark){
            ans[getpar(yal[i].x)]+=yal[i].w;
        }
    }

    for (int i = 1 ; i <= n ; i ++){
        if(depth[i] == 0){
            son[i][0]  = 1e6;
            dad[i][0] = i;
            depth[i] = 1;
            dfs2(i);
        }
    }
    //cout << 2;
    sort(yal +1,yal + m + 1 , cmp2 );
    //cout << 2;
    preprocess(1);
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        int x = yal[i].x , y = yal[i] . y;
        int lc = lca(x , y);
        if(yal[i].mark){
            cout << ans[getpar(x)] << endl;
        }
        else{
            ll mx = max(pht(x , lc) , pht(y , lc));
            //cout << lc << endl;
            cout << (ll)ans[getpar(x)] - mx + yal[i].w << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

const ll maxn =10e5+10;
const ld SADAT = 7.84e-17;
const ll INF = 1e9;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>bool checkmin(T &a,T b){return a > b ? a = b, 1 : 0;}
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}
struct edge{
    int t , w , next;
}e[maxn];
int n, l , m , g[maxn];
vector<int> adj[maxn];
vector< pii > vec[maxn];
int timer;
vector<int> tin, tout;
vector<vector<int> > up;
bool inmst[maxn];
int par[maxn];
vector <int> comp[maxn];
int ans[maxn];
int depth[maxn] , son[maxn][20] , dad[maxn][20];
int cnt ;
struct yaint{
        int x , y , w , mark , k;
}yal[maxn];

bool cmp(yaint i , yaint j){
    return(i.w < j.w);
}

void dfs2(int v){
    for(int i=1;i<20;i++){
        dad[v][i]=dad[dad[v][i-1]][i-1];
        son[v][i]=max(son[dad[v][i-1]][i-1],son[v][i-1]);
    }
    for(int i=g[v];i;i=e[i].next){
        if(!depth[e[i].t]){
            depth[e[i].t]=depth[v]+1;
            dad[e[i].t][0]=v;
            son[e[i].t][0]=e[i].w;
            dfs2(e[i].t);
        }
    }
}

void add(int x,int y,int z){
    e[++cnt].t=y;
    e[cnt].w=z;
    e[cnt].next=g[x];
    g[x]=cnt;
}

int getpar(int v){
    if(par[v] == v){
        return(v);
    }
    par[v] = getpar(par[v]);
    return(par[v]);
}

void dfs(int v, int p){
    tin[v] = ++timer;
    //cout << v;
    up[v][0] = p;
    for (int i = 1; i <= l; ++i){
        up[v][i] = up[up[v][i-1]][i-1];
        //cout << l << '\t';
    }
    for (int i = 0 ; i < adj[v].size() ; i ++) {
        int u = adj[v][i];
        if(v == 3){
            //cout << u;
        }
        if (u!=p){
            dfs(u, v);
        }
    }
    //cout << v;
    tout[v] = ++timer;
    //cout << v;
}

bool is_ancestor(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

bool cmp2(yaint i , yaint j){
    return(i.k < j . k );
}

int lca(int u, int v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = l; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}

void preprocess(int root) {
    tin.resize(n*2);
    tout.resize(n*2);
    timer = 0;
    l = ceil(log2(n));
    up.assign(n * 2, vector<int>(l + 1));
    dfs(root, root);

    //cout << 2;s
}

int pht(int x,int y){
    int h=depth[x]-depth[y],mx=0;
    for(int i = 0 ; h ; i ++){
        if(h & 1){
            mx=max(mx,son[x][i]);
            x=dad[x][i];
        }
        h>>=1;
    }
    return mx;
}

int main(){
    //migmig
    cin >> n >> m;
    for (int i = 1 ;i <= m; i ++){
        int x , y , w;
        cin >> x >> y >> w;
        vec[x].pb(make_pair(w , y));
        vec[y].pb(make_pair(w , x));
        yal[i].x = x , yal[i].y = y , yal[i].k = i , yal[i].w = w;
    }
    sort(yal + 1 , yal + m + 1, cmp);
    for (int i = 0 ; i < n ; i ++){
        par[i + 1] = i + 1;
    }
    for (int i = 1 ; i <= n ; i ++){
        if(getpar(yal[i].x) != getpar(yal[i].y)){
            yal[i].mark = 1;
            int x = yal[i].x , y = yal[i].y;
            adj[x].pb(y);
            //cout << 2;
            adj[y].pb(x);
            //cout << 2;
            par[par[yal[i].x]] = par[yal[i].y];
            add(yal[i].x , yal[i].y , yal[i].w);
            add(yal[i].y , yal[i].x , yal[i].w);
        }
    }
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        if(yal[i].mark){
            ans[getpar(yal[i].x)]+=yal[i].w;
        }
    }

    for (int i = 1 ; i <= n ; i ++){
        if(depth[i] == 0){
            son[i][0]  = 1e10;
            dad[i][0] = i;
            depth[i] = 1;
            dfs2(i);
        }
    }
    //cout << 2;
    sort(yal +1,yal + m + 1 , cmp2 );
    //cout << 2;
    preprocess(1);
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        int x = yal[i].x , y = yal[i] . y;
        int lc = lca(x , y);
        if(yal[i].mark){
            cout << ans[getpar(x)] << endl;
        }
        else{
            int mx = max(pht(x , lc) , pht(y , lc));
            //cout << lc << endl;
            cout << (int)ans[getpar(x)] - mx + yal[i].w << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you wiint come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.