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.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class C {

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    static boolean Vist[];
    static List<List<node>> Ady;
    static PriorityQueue<node> Q;
    static long Dist[];
    static long INF = Long.MAX_VALUE;

    static class node implements Comparable<node> {

        int node;
        long weight;

        public node(int node, long weight) {
            this.node = node;
            this.weight = weight;
        }

        public int compareTo(node o) {
            return (weight - o.weight < 0) ? -1 : (weight - o.weight == 0) ? 0 : 1;
        }
    }

    static void relax(int actual, int ady, long peso) {
        if (Dist[actual] + peso < Dist[ady]) {
            Dist[ady] = Dist[actual] + peso;
            Q.add(new node(ady, Dist[ady]));
        }
    }

    static void dijkstra(int ini) {
        Q.add(new node(ini, 0));
        Dist[ini] = 0;
        int actual, Tady; 
        long peso;
        while (!Q.isEmpty()) {
            actual = Q.poll().node;
            if (Vist[actual]) {
                continue;
            }
            Vist[actual] = true;
            for (int i = 0; i < Ady.get(actual).size(); i++) {
                List<node> adyActual = Ady.get(Ady.get(actual).get(i).node);
                long w1 = Ady.get(actual).get(i).weight;
                for (int j = 0; j < adyActual.size(); j++) {
                    Tady = adyActual.get(j).node;
                    if(Tady == actual) continue;
                    long w2 = adyActual.get(j).weight;
                    peso = (w1+w2)*(w1+w2);
                    if (!Vist[Tady]) {
                        relax(actual, Tady, peso);
                    }
                }
            }
        }
    }

    static void ini(int n) {

        Vist = new boolean[n];
        Ady = new ArrayList<List<node>>();
        Dist = new long[n];
        Q = new PriorityQueue<node>();
        Arrays.fill(Dist, INF);
        for (int i = 0; i < n; i++) {
            Ady.add(new ArrayList<node>());
        }
    }//END DYKSTRA 

    public static void main(String[] args) throws IOException {
        FastReader fr = new FastReader();
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        int n, m;
        n = fr.nextInt();
        m = fr.nextInt();
        ini(n);
        for (int i = 0; i < m; i++) {
            int f, t, w;
            f = fr.nextInt() - 1;
            t = fr.nextInt() - 1;
            w = fr.nextInt();
            Ady.get(f).add(new node(t, w));
            Ady.get(t).add(new node(f, w));
        }

        dijkstra(0);

        for (int i = 0; i < Dist.length; i++) {
            if(Dist[i] == Long.MAX_VALUE){
                pw.print("-1 ");
            }else{
                pw.print(Dist[i]+" ");
            }
            
        }
        pw.println();
        pw.flush();
    }
}