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 <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
#include <ctype.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = (1LL<<60)-1;

#define rep(i, n) for (int i = 0; i < n; i++)

template<class T> 
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}

template<class T> 
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}

typedef pair<int,int> P;
typedef pair<ll,P> lP;

struct edge {
    int to;
    ll cost;
    edge(int to, ll cost): to(to), cost(cost) {};
};

void dijkstra(vector<vector<edge> >&G, int s, vector<vector<ll> > &dist) {
    dist.resize(G.size());
    for (int i = 0; i < G.size(); i++)
        dist[i].resize(51, LINF);
    
    priority_queue<lP, vector<lP>, greater<lP> > que;
    que.push(lP(0, P(s, 0)));
    dist[s][0] = 0;
    while (que.size()) {
        lP p = que.top();    que.pop();
        int u = p.second.first;   ll d = p.first, w = p.second.second;
        if (dist[u][w] < d)    continue;
        if (w == 0) {
            for (auto e: G[u]) {
                int v = e.to;   ll c = e.cost;
                if (chmin(dist[v][c], d))
                    que.push(lP(dist[v][c], P(v, c)));
            }
        }
        else {
            for (auto e: G[u]) {
                int v = e.to;   ll c = e.cost;
                if (chmin(dist[v][0], d + (w+c)*(w+c)))
                    que.push(lP(dist[v][0], P(v, 0)));
            }
        }
    }
}

int main() {    
    int n, m;   cin >> n >> m;
    vector<vector<edge> > G(n);
    rep(i, m) {
        int u, v;   ll w;   cin >> u >> v >> w;
        u--;    v--;
        G[u].push_back(edge(v, w));
        G[v].push_back(edge(u, w));
    }
    vector<vector<ll> > dist;
    dijkstra(G, 0, dist);
    rep(i, n) {
        if (dist[i][0] < LINF)
            cout << dist[i][0] << " ";
        else 
            cout << -1 << " ";
    }
    cout << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;