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.util.*;
import java.io.*;
public class A{
    
    public static void main(String [] args)throws IOException{
        // BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int test=1;
         
        while(test-->0){
            
           
            int n=sc.nextInt();
            int m=sc.nextInt();

            ArrayList<Pair> arr[]=new ArrayList[n+1];
            for(int i=0;i<=n;i++) arr[i]=new ArrayList<Pair>();

         
            while(m-->0){
            
                int source=sc.nextInt();
                int dest = sc.nextInt();
                int weight = sc.nextInt();
                arr[source].add(new Pair(dest,weight));
                arr[dest].add(new Pair(source,weight));
            }
          
            int [][] d=djikstra(1,n,arr);

            for(int i=1;i<=n;i++){
                if(d[i][0] == Integer.MAX_VALUE) d[i][0]=-1;
               pw.print(d[i][0]+" ");
            }
            pw.println();
            pw.close();
        }
    }

    static class Pair{
        int dest=0;
        int wt=0;
        Pair(){}
        Pair(int d,int w){
            dest=d;
            wt =w;
        }
    }
    static class customSort implements Comparator<Pair>{
        public int compare(Pair a,Pair b){
            if(a.wt<b.wt){
                return -1;
            }
            else if(a.wt>b.wt){
                return 1;
            }
            return 0;
        }
    }

    public static int [][] djikstra(int source,int n,ArrayList<Pair> arr[]){
    		int dist[][]=new int[n+1][52];
    		boolean vis[][]=new boolean[n+1][52];
    		for(int i=0;i<=n;i++) Arrays.fill(dist[i], Integer.MAX_VALUE);
    		
    		PriorityQueue<Pair> pq=new PriorityQueue<>(new customSort());
    		pq.add(new Pair(1*55+0,0));
    		
    		while(!pq.isEmpty()) {
    			Pair x=pq.poll();
    			int nd =x.dest/55;
    			int lastEdgWt =x.dest%55;
    			int distance =x.wt;
    			
    			if(vis[nd][lastEdgWt]) {
    				continue;
    			}
    			
    			vis[nd][lastEdgWt]=true;
    			dist[nd][lastEdgWt]=distance;
    			
    			for(Pair y:arr[nd]) {
    				int newWt= y.wt;
    				int newDistance =distance;
    				if(lastEdgWt>0) {
    					newDistance +=((newWt+lastEdgWt)*(newWt+lastEdgWt));
    					newWt=0;
    				}
    				if(dist[y.dest][newWt] <= newDistance) continue;
    				
    				dist[y.dest][newWt] =newDistance;
    				pq.add(new Pair(((y.dest*55)+newWt),newDistance));
    			}
    		}
    	
    	
    	
            return dist;
    }



    /**
     * Fast I/O
     */
    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()); 
		} 
 
		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 
 
		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	} 

}