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;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
//#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007 //998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1000000005
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
int vis[N][51];
vector<pii>adj[N];
int dis[N][51];
struct comp{
    bool operator()(array<int,3> const& a1,array<int,3> const& a2)
    {
        return a1[0]>a2[0];
    }
};
void solve()
{
    int n,m;
    cin>>n>>m;
    rep(i,0,m)
    {
        int u,v,w;
        cin>>u>>v>>w;
        adj[u].pb({v,w});
        adj[v].pb({u,w});
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<51;j++)
            dis[i][j]=INF;
    }
    dis[1][0]=0;
    priority_queue<array<int,3>,vector<array<int,3>>,comp>pq;//dis,ver,last_w
    pq.push({0,1,0});
    while(!pq.empty())
    {
        int d = pq.top()[0];
        int u = pq.top()[1];
        int lw =pq.top()[2];
        pq.pop();
        if(vis[u][lw])continue;
        vis[u][lw]=1;
        dis[u][lw]=d;
        for(auto v:adj[u])
        {
            int newd = d;
            if(lw)newd += (v.S + lw)*(v.S + lw);
            int nlw = v.S;
            if(lw)nlw=0;
            if(vis[v.F][nlw])continue;
            if(dis[v.F][nlw] <= newd)continue;
            pq.push({newd,v.F,nlw});
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(dis[i][0] == INF)
        {
            cout<<-1<<" ";
        }
        else
        {
            cout<<dis[i][0]<<" ";
        }
    }
    cout<<endl;


}
int main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int tests;
   //cin>>tests;
   tests=1;
   for(int i=0;i<tests;i++)
   {
       solve();
   }
}
