There are n cities and m bidirectional roads in the country. The roads in the country form an undirected weighted graph. The graph is not guaranteed to be connected. Each road has it's own parameter w. You can travel through the roads, but the government made a new law: you can only go through two roads at a time (go from city a to city b and then from city b to city c) and you will have to pay (w_{ab} + w_{bc})^2 money to go through those roads. Find out whether it is possible to travel from city 1 to every other city t and what's the minimum amount of money you need to get from 1 to t.

Input

First line contains two integers n, m (2 ≤ n ≤ 10^5, 1 ≤ m ≤ min((n ⋅ (n - 1))/(2), 2 ⋅ 10^5)).

Next m lines each contain three integers v_i, u_i, w_i (1 ≤ v_i, u_i ≤ n, 1 ≤ w_i ≤ 50, u_i ≠ v_i). It's guaranteed that there are no multiple edges, i.e. for any edge (u_i, v_i) there are no other edges (u_i, v_i) or (v_i, u_i).

Output

For every city t print one integer. If there is no correct path between 1 and t output -1. Otherwise print out the minimum amount of money needed to travel from 1 to t.

Examples

Input


5 6
1 2 3
2 3 4
3 4 5
4 5 6
1 5 1
2 4 2


Output


0 98 49 25 114 

Input


3 2
1 2 1
2 3 2


Output


0 -1 9 

Note

The graph in the first example looks like this.

<image>

In the second example the path from 1 to 3 goes through 2, so the resulting payment is (1 + 2)^2 = 9.

<image>
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr ll KINF = 1e14;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<PII>> g(n);
	_rep(i, 0, m){
		int u, v, w;
		cin >> u >> v >> w;
		g[--u].eb(--v, w);
		g[v].eb(u, w);
	}
	int M = 51;
	PQ<pair<ll,int>> pq;
	VL d(M * n, KINF);
	d[0] = 0;
	pq.emplace(0, 0);
	while(!pq.empty()){
		auto [dist, t] = pq.top();
		pq.pop();
		dist = -dist;
		if(dist > d[t]) continue;
		int u = t / M, w = t % M;
		if(!w){//上次的点不是中转点
			for(auto& [vv, ww] : g[u]){
				int nxt = vv * M + ww;
				if(d[nxt] > d[t]){
					d[nxt] = d[t];
					pq.emplace(-d[nxt], nxt);
				}
			}
		}
		else{
			for(auto& [vv, ww] : g[u]){
				int nxt = vv * M;
				if(d[nxt] > d[t] + 1ll * (ww + w) * (ww + w)){
					d[nxt] = d[t] + 1ll * (ww + w) * (ww + w);
					pq.emplace(-d[nxt], nxt);
				}
			}
		}
	}
	_rep(i, 0, n) cout << (d[i * M] == KINF ? -1 : d[i * M]) << " \n"[i == n - 1];
	return 0;
} 
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline

