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.util.*;

public class Main2{
	static int INF=(int)2e9;
	static ArrayList<int[]>[] adjListW;
	static int n;
	static int[] dijkstra(int S)	//O(E log E)
	{
		int[][][] dist = new int[2][51][n];
		for(int i=0;i<2;i++) {
			for(int j=0;j<=50;j++) {
				for(int o=0;o<n;o++)dist[i][j][o]=INF;
			}
		}
		PriorityQueue<int[]> pq = new PriorityQueue<int[]>((x,y)->x[0]-y[0]);
		dist[0][0][S] = 0;
		pq.add(new int[] {0,0,0,S});
		while(!pq.isEmpty())
		{
			int[] cur = pq.remove();
			int node=cur[3],cost=cur[0],p=cur[1],prevW=cur[2];
			if(cost > dist[p][prevW][node])
				continue;
			for(int[] nxt: adjListW[node]) {
				if(p==0) {
					if(cost < dist[1][nxt[1]][nxt[0]])
						pq.add(new int[] {dist[1][nxt[1]][nxt[0]] = cost,1,nxt[1],nxt[0]});
				}
				else {
					int curCost=(prevW+nxt[1])*(prevW+nxt[1]);
					if(cost + curCost < dist[0][0][nxt[0]])
						pq.add(new int[] {dist[0][0][nxt[0]] = cost+curCost,0,0,nxt[0]});
				}
			}
		}
		int[]ans=new int[n];
		for(int i=0;i<n;i++)ans[i]=dist[0][0][i]==INF?-1:dist[0][0][i];
		return ans;
	}
    static void main() throws Exception{
    	n=sc.nextInt();int m=sc.nextInt();
    	adjListW=new ArrayList[n];
    	for(int i=0;i<n;i++)adjListW[i]=new ArrayList<int[]>();
    	for(int i=0;i<m;i++) {
    		int x=sc.nextInt()-1,y=sc.nextInt()-1,w=sc.nextInt();
    		adjListW[x].add(new int[] {y,w});
    		adjListW[y].add(new int[] {x,w});
    	}
    	int[]ans=dijkstra(0);
    	for(int i=0;i<n;i++)pw.print(ans[i]+ " ");
    	pw.println();
    }
    public static void main(String[] args) throws Exception{
        sc=new MScanner(System.in);
        pw = new PrintWriter(System.out);
        int tc=1;
//        tc=sc.nextInt();
        for(int i=1;i<=tc;i++) {
//            pw.printf("Case %d:\n", i);
            main();
        }
        pw.flush();
    }
    static PrintWriter pw;
    static MScanner sc;
    static class MScanner {
        StringTokenizer st;
        BufferedReader br;
        public MScanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }
     
        public MScanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }
     
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public int[] intArr(int n) throws IOException {
            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public long[] longArr(int n) throws IOException {
            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public int[] intSortedArr(int n) throws IOException {
            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
            shuffle(in);
            Arrays.sort(in);
            return in;
        }
        public long[] longSortedArr(int n) throws IOException {
            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            shuffle(in);
            Arrays.sort(in);
            return in;
        }
        public Integer[] IntegerArr(int n) throws IOException {
            Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public Long[] LongArr(int n) throws IOException {
            Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }
     
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
     
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
     
        public char nextChar() throws IOException {
            return next().charAt(0);
        }
     
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
     
        public boolean ready() throws IOException {
            return br.ready();
        }
     
        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }
        
    }
    static void shuffle(int[]in) {
        for(int i=0;i<in.length;i++) {
            int idx=(int)(Math.random()*in.length);
            int tmp=in[i];
            in[i]=in[idx];
            in[idx]=tmp;
        }
    }
    static void shuffle(long[]in) {
        for(int i=0;i<in.length;i++) {
            int idx=(int)(Math.random()*in.length);
            long tmp=in[i];
            in[i]=in[idx];
            in[idx]=tmp;
        }
    }
}