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 java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.AbstractCollection;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Khater
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EPairedPayment solver = new EPairedPayment();
        solver.solve(1, in, out);
        out.close();
    }

    static class EPairedPayment {
        long INF = (long) 1e15;
        ArrayList<EPairedPayment.Edge>[] adjList;
        long[] dist;
        long[] dist2;
        int V;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int t = 1;
            // t = sc.nextInt();
            while (t-- > 0) {
                int n = sc.nextInt();
                int m = sc.nextInt();
                V = n;
                adjList = new ArrayList[n];
                for (int i = 0; i < n; i++) adjList[i] = new ArrayList<>();
                for (int i = 0; i < m; i++) {
                    int x = sc.nextInt() - 1;
                    int y = sc.nextInt() - 1;
                    long w = sc.nextLong();
                    adjList[x].add(new EPairedPayment.Edge(y, w));
                    adjList[y].add(new EPairedPayment.Edge(x, w));
                }
            }
            dijkstra(0, -1);
            for (long x : dist) pw.print((x == (long) 1e15 ? -1 : x) + " ");
            pw.println();

        }

        long dijkstra(int S, int T) {
            dist = new long[V];
            Arrays.fill(dist, INF);
            dist2 = new long[V];
            Arrays.fill(dist2, INF);
            PriorityQueue<EPairedPayment.Edge> pq = new PriorityQueue<EPairedPayment.Edge>();
            dist[S] = 0;
            pq.add(new EPairedPayment.Edge(S, 0));                        //may add more in case of MSSP (Mult-Source)
            while (!pq.isEmpty()) {
                EPairedPayment.Edge cur = pq.remove();
                if (cur.cost > dist[cur.node])            //lazy deletion
                    continue;
                for (EPairedPayment.Edge nxt : adjList[cur.node]) {
                    if (dist2[nxt.node] > nxt.cost) {
                        for (EPairedPayment.Edge nxtnxt : adjList[nxt.node]) {
                            if (nxtnxt.node != cur.node)
                                if (cur.cost + (nxt.cost + nxtnxt.cost) * (nxt.cost + nxtnxt.cost) < dist[nxtnxt.node])
                                    pq.add(new EPairedPayment.Edge(nxtnxt.node, dist[nxtnxt.node] = cur.cost + (nxt.cost + nxtnxt.cost) * (nxt.cost + nxtnxt.cost)));
                        }
                        dist2[nxt.node] = nxt.cost;
                    }
                }
            }
            return -1;
        }

        static class Edge implements Comparable<EPairedPayment.Edge> {
            int node;
            long cost;

            Edge(int a, long b) {
                node = a;
                cost = b;
            }

            public int compareTo(EPairedPayment.Edge e) {
                return Long.compare(cost, e.cost);
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

