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 os
import sys
from io import BytesIO, IOBase

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#https://github.com/cheran-senthil/PyRival/blob/master/templates/template_py3.py


import heapq
 
n,m=map(int,input().split())
edges=[[] for i in range (n+1)]

for _ in range(m):
    a,b,w=map(int,input().split())
    edges[a].append((b,w))
    edges[b].append((a,w))
    
heap=[(0,0,1)]
min_distance=[[float('inf')]*51 for _ in range(n+1)]
min_distance[1][0]=0 #base case
#Note that in this problem, a single node maybe relaxed more than once. This is because we can take a squence whose sum is longer than the shortest path, but squared distance is shorter. For ex: 10+10 < 10+1+10+1 but (10+10)^2> (10+1)^2 + (10+1)^2 etc.
#If we "keep track" of every prev node for every node, it'll be O(n^2)=>TLE 
#So,Key is to "keep track" of the edge(rather the node)with a particular weight(as only 50 possibilities) incoming to the node only once.(As this won't affect the answer for outgoing nodes anyway). We don't need to check every  
#Normal dijkstra ("relaxing" can be thought of as min_distance to a node with a given prev weight now)
while heap:
    distance,prev_weight,node=heapq.heappop(heap) #Prev_weight wrt new/next node
    if(distance>min_distance[node][prev_weight]):
        continue
    for j,w in edges[node]:
        if(prev_weight==0): #i.e middle node encountered(can't be reached), this 0 has no significance, it is just a value taken to minimize the dimensions of the array.
            if(min_distance[j][w]>distance):
                min_distance[j][w]=distance
                heapq.heappush(heap,(min_distance[j][w],w,j)) #Current weight will be included for the next outgoing node from this middle node
        else:
            if(min_distance[j][0]>distance+pow(prev_weight+w,2)):
                min_distance[j][0]=distance+pow(prev_weight+w,2) #the 0th index of weight stores  the overall allowed min weight possible(i.e. not from a neighbouring node to it)
                heapq.heappush(heap,(min_distance[j][0],0,j)) #Now after a node is reached by a legal path, nodes directly connected to this cann't be reached from this node directly. So we set it's prev_weight(flag) to the forbidden value 0.
ans=[]
for i in range(1,n+1):
    if(min_distance[i][0]==float('inf')):
        ans.append(-1)
    else:
        ans.append(min_distance[i][0])
print(*ans)
