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>
import sys
import math
import collections
import bisect
import itertools
import decimal
import heapq


# sys.setrecursionlimit(10000001)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353


def ni(): return int(sys.stdin.buffer.readline())
def ns(): return map(int, sys.stdin.buffer.readline().split())
def na(): return list(map(int, sys.stdin.buffer.readline().split()))
def na1(): return list(map(lambda x: int(x)-1, sys.stdin.buffer.readline().split()))
def flush(): return sys.stdout.flush()


def nicf(): return int(sys.stdin.readline())
def nscf(): return map(int, sys.stdin.readline().split())
def nacf(): return list(map(int, sys.stdin.readline().split()))
def na1cf(): return list(map(lambda x: int(x)-1, sys.stdin.readline().split()))


# ===CODE==
# def solve():
#     return

def dijkstra(e, s):
    n = len(e)
    hq = []
    heapq.heappush(hq, (0, s))
    mnd = [INF]*n
    mnd[0] = 0

    while hq:
        d, idx = heapq.heappop(hq)
        if d > mnd[idx]:
            continue

        for ei, ci in e[idx]:
            nd = d+ci
            if mnd[ei] > nd:
                mnd[ei] = nd
                heapq.heappush(hq, (nd, ei))

    # 返すのはsから各ノードへの最短距離
    return mnd


def main():
    n, m = ns()
    e = [[] for _ in range(n)]
    for _ in range(m):
        a, b, w = ns()
        a, b, = a-1, b-1
        e[a].append([b, w])
        e[b].append([a, w])

    def dijkstra(e, s):
        hq = []
        heapq.heappush(hq, (0, s))
        mnd = [INF]*n
        mnd[0] = 0

        while hq:
            d, idx = heapq.heappop(hq)
            if d > mnd[idx]:
                continue

            for ei, ci0 in e[idx]:
                for nei, ci1 in e[ei]:
                    if nei == idx:
                        continue

                    wi = (ci0+ci1)**2

                    nd = d+wi
                    if mnd[nei] > nd:
                        mnd[nei] = nd
                        heapq.heappush(hq, (nd, nei))

        # 返すのはsから各ノードへの最短距離
        return mnd

    res = dijkstra(e, 0)
    for i in range(n):
        if res[i] == INF:
            res[i] = -1
    print(*res)


if __name__ == '__main__':
    main()
