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>
// Don't place your source in a package
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;


// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

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

        String Str(){
            return next();
        }
    }


    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(System.out);



        int T=1;
        for(int t=0;t<T;t++){
            int n=Int();int m=Int();
            List<int[]>g[]=new ArrayList[n];
            for(int i=0;i<g.length;i++){
                g[i]=new ArrayList<>();
            }

            for(int i=0;i<m;i++){
                int u=Int()-1,v=Int()-1,w=Int();
                g[u].add(new int[]{v,w});
                g[v].add(new int[]{u,w});
            }


            Solution sol=new Solution();
            sol.solution(out,g);
        }
        out.flush();

    }

    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}



class Solution{
    public void solution(PrintWriter out,List<int[]>g[]){
        int n=g.length;
        int dis[][][]=new int[51][n][2];
        for(int i=0;i<dis.length;i++){
            for(int j=0;j<dis[0].length;j++){
                Arrays.fill(dis[i][j],Integer.MAX_VALUE);
            }
        }


        PriorityQueue<int[]>q=new PriorityQueue<>((a,b)->{
            return a[3]-b[3];
        });
        q.add(new int[]{0,0,0,0});
        dis[0][0][0]=0;


        while(q.size()>0){
            int top[]=q.poll();
            int pre=top[0],root=top[1],level=top[2];
            level%=2;
            if(top[3]!=dis[pre][root][level])continue;

            for(int p[]:g[root]){
                int next=p[0],w=p[1];
                int mn=Integer.MAX_VALUE;
                if(level%2==0){
                    mn=Math.min(mn,dis[pre][root][level]);
                }
                else{
                    mn=Math.min(mn,dis[pre][root][level]+(pre+w)*(pre+w));
                }


                if(mn!=Integer.MAX_VALUE && dis[w][next][(level+1)%2]>mn){
                    dis[w][next][(level+1)%2]=mn;
                    q.add(new int[]{w,next,(level+1)%2,mn});
                }
            }

        }



        for(int i=0;i<dis[0].length;i++){
            int mn=Integer.MAX_VALUE;
            for(int j=0;j<dis.length;j++){
                mn=Math.min(mn,dis[j][i][0]);
            }
            if(mn==Integer.MAX_VALUE)out.print("-1 ");
            else out.print(mn+" ");
        }
    }


}


