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 E {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<Edge>[] g = new ArrayList[n];
		for(int i = 0; i < n; i++){
			g[i] = new ArrayList<>();
		}
		for(int i = 0; i < m; i++){
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			int w = sc.nextInt();
			g[u].add(new Edge(v, w));
			g[v].add(new Edge(u, w));
		}
		long maxv = 2000000000;
		PriorityQueue<Pair> q = new PriorityQueue<>();
		long[][] dist = new long[n][51];
		boolean[][] seen = new boolean[n][51];
		for(int i = 0; i < n; i++){
			Arrays.fill(dist[i], maxv);
		}
		dist[0][0] = 0;
		q.add(new Pair(0, 0, 0));
		while(!q.isEmpty()) {
			Pair p = q.poll();
			if(seen[p.u][p.k]) continue;
			seen[p.u][p.k] = true;
			for(Edge e: g[p.u]) {
				if(p.k == 0) {
					if(dist[e.u][e.w] > p.w) {
						dist[e.u][e.w] = p.w;
						q.add(new Pair(e.u, e.w, p.w));
					}
				}
				else {
					long ww = p.w + (p.k + e.w) * (p.k + e.w);
					if(dist[e.u][0] > ww) {
						dist[e.u][0] = ww;
						q.add(new Pair(e.u, 0, ww));
					}
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++){
			if(dist[i][0] == maxv) sb.append("-1 ");
			else sb.append(dist[i][0]+" ");
		}
		sb.replace(sb.length()-1, sb.length(), "\n");
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(sb.toString().trim());
		pw.flush();
	}
	static class Edge{
		int u, w;
		public Edge(int u, int w){
			this.u = u; this.w = w;
		}
		public String toString(){
			return u + " " + w;
		}
	}
	static class Pair implements Comparable<Pair>{
		int u, k; long w;
		public Pair(int u, int k, long w){
			this.u = u; this.k = k; this.w = w;
		}
		public int compareTo(Pair p){
			return Long.compare(w, p.w);
		}
			
		public String toString(){
			return u + ", " + k + ": " + w;
		}
	}
	
	
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}

}
