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 tr1 {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = (long) 1e9 + 7;
	static int[] memo;
	static int[][][] memo1;
	static int n, m;
	static ArrayList<long[]>[] ad;
	static HashMap<Integer, Integer>[] going;
	static long inf = Long.MAX_VALUE;
	static char[][] g;
	static boolean[] vis;
	static int[] dep;
	static int hh;
	static HashMap<Integer, Integer> hmC, hmG;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		m = sc.nextInt();
		ad = new ArrayList[n];
		for (int i = 0; i < n; i++)
			ad[i] = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			int w = sc.nextInt();
			ad[a].add(new long[] { b, w });
			ad[b].add(new long[] { a, w });
		}
		long INF = Long.MAX_VALUE;
		long[] dist = new long[n];
		Arrays.fill(dist, INF);
		PriorityQueue<long[]> pq = new PriorityQueue<long[]>((x, y) -> Long.compare(x[1], y[1]));
		dist[0] = 0;
		pq.add(new long[] { 0, 0 });
		long[] vis1 = new long[n];
		Arrays.fill(vis1, INF);
		while (!pq.isEmpty()) {
			long[] cur = pq.remove();
			if (cur[1] > dist[(int) cur[0]])
				continue;
			int u = (int) cur[0];
			long cost = cur[1];
			ArrayList<long[]> fresh = new ArrayList<>();
			for (long[] v : ad[u])
				if (vis1[(int) v[0]] <= v[1])
					continue;
				else {
					vis1[(int) v[0]] = v[1];
					fresh.add(new long[] { v[0], v[1] });
				}
			for (long[] y : fresh) {
				for (long[] v : ad[(int) y[0]])
					if (dist[(int) v[0]] > cost + (v[1] + y[1]) * (v[1] + y[1])) {
						dist[(int) v[0]] = cost + (v[1] + y[1]) * (v[1] + y[1]);
						pq.add(new long[] { v[0], dist[(int) v[0]] });
					}
			}
		}
		for (int i = 0; i < n; i++)
			if (dist[i] == Long.MAX_VALUE)
				out.print(-1 + " ");
			else
				out.print(dist[i] + " ");
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(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 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 int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public int[] nextArrIntSorted(int n) throws IOException {
			int[] a = new int[n];
			Integer[] a1 = new Integer[n];
			for (int i = 0; i < n; i++)
				a1[i] = nextInt();
			Arrays.sort(a1);
			for (int i = 0; i < n; i++)
				a[i] = a1[1].intValue();
			return a;
		}

		public long[] nextArrLongSorted(int n) throws IOException {
			long[] a = new long[n];
			Long[] a1 = new Long[n];
			for (int i = 0; i < n; i++)
				a1[i] = nextLong();
			Arrays.sort(a1);
			for (int i = 0; i < n; i++)
				a[i] = a1[1].longValue();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}