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>
/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2021/3/9 11:42 下午
*
================================================================*/
#include <bits/stdc++.h>

#define VI vector<int>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
using namespace std;

namespace IO {
    template<class T>
    void _R(T &x) { cin >> x; }
    void _R(int &x) { scanf("%d", &x); }
    void _R(ll &x) { scanf("%lld", &x); }
    void _R(double &x) { scanf("%lf", &x); }
    void _R(char &x) { x = getchar(); }
    void _R(char *x) { scanf("%s", x); }
    void R() {}
    template<class T, class... U>
    void R(T &head, U &... tail) { _R(head), R(tail...); }
    template<class T>
    void _W(const T &x) { cout << x; }
    void _W(const int &x) { printf("%d", x); }
    void _W(const ll &x) { printf("%lld", x); }
    void _W(const double &x) { printf("%.16f", x); }
    void _W(const char &x) { putchar(x); }
    void _W(const char *x) { printf("%s", x); }
    template<class T, class U>
    void _W(const pair<T, U> &x) { _W(x.first), putchar(' '), _W(x.second); }
    template<class T>
    void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
    void W() {}
    template<class T, class... U>
    void W(const T &head, const U &... tail) { _W(head), putchar(sizeof...(tail) ? ' ' : '\n'), W(tail...); }
}
using namespace IO;


const int maxn = 1e5 + 50;
const int mod = 1e9 + 7;

ll qp(ll a, ll n) {
    ll res = 1;
    n %= mod - 1;
    if (n < 0) n += mod - 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll qp(ll a, ll n, int mod) {
    ll res = 1;
    n %= mod - 1;
    if (n < 0) n += mod - 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int dist[maxn][55];
int n, m;
vector<pair<int, int> > edge[maxn];

struct node {
    int u, val, pre;
    bool operator<(const node &oth) const {
        return val > oth.val;
    }
};

int main(int argc, char *argv[]) {
    R(n, m);
    for (int i = 0; i < m; ++i) {
        int u, v, w;
        R(u, v, w);
        edge[u].emplace_back(v, w);
        edge[v].emplace_back(u, w);
    }
    memset(dist, -1, sizeof dist);
    priority_queue<node> qu;
    dist[1][0] = 0;
    qu.push({1, 0, 0});
    while (!qu.empty()) {
        node tmp = qu.top();
        qu.pop();
        int u = tmp.u;
        if (dist[u][tmp.pre] != tmp.val) continue;
        if (tmp.pre == 0) {
            for (auto &it : edge[u]) {
                int v = it.first;
                int w = it.second;
                if (dist[v][w] == -1 || dist[v][w] > tmp.val) {
                    dist[v][w] = tmp.val;
                    qu.push({v, tmp.val, w});
                }
            }
        } else {
            for (auto &it : edge[u]) {
                int v = it.first;
                int w = tmp.val + (tmp.pre + it.second) * (tmp.pre + it.second);
                if (dist[v][0] == -1 || dist[v][0] > w) {
                    dist[v][0] = w;
                    qu.push({v, w, 0});
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) printf("%d%c", dist[i][0], " \n"[i == n]);
    return 0;
}