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

	static class node implements Comparable<node> {
		int node, p;
		Cost cost;

		node(int u, int par, Cost c) {
			node = u;
			p = par;
			cost = c;
		}

		@Override
		public int compareTo(node o) {
			// TODO Auto-generated method stub
			return cost.compareTo(o.cost);
		}
	}

	static class Cost {
		long cost;
		int last;

		Cost(long c, int l) {
			cost = c;
			last = l;
		}

		public int compareTo(Cost other) {
			if (cost != other.cost)
				return Long.compare(cost, other.cost);
			return last - other.last;
		}
	}

	static int n, m;
	static ArrayList<int[]> adj[];
	static long INF = (long) 1e18;

	static long[] solve() {
		PriorityQueue<node> pq = new PriorityQueue();

		long[][] dist2 = new long[n][51];
		long[] dist = new long[n];
		Arrays.fill(dist, INF);
		for (long[] x : dist2)
			Arrays.fill(x, INF);
		dist[0] = 0;
		pq.add(new node(0, 0, new Cost(0, 0)));

		while (!pq.isEmpty()) {
			node curr = pq.poll();
			int u = curr.node, p = curr.p;
			Cost cost = curr.cost;
			if (p == 0 && cost.cost > dist[u])
				continue;
			if (p == 1 && cost.cost > dist2[u][cost.last])
				continue;
			for (int[] nxt : adj[u]) {
				int v = nxt[0];
				int w = nxt[1];
				if (p == 0) {
					if (dist2[v][w] > cost.cost)
						pq.add(new node(v, p ^ 1, new Cost(dist2[v][w] = cost.cost, w)));

				} else {
					long total = cost.cost + (w + cost.last) * 1L * (w + cost.last);
					if (dist[v] > total)
						pq.add(new node(v, p ^ 1, new Cost(dist[v] = total, 0)));
				}
			}
		}

		return dist;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		n = sc.nextInt();
		m = sc.nextInt();
		adj = new ArrayList[n];
		for (int i = 0; i < n; i++)
			adj[i] = new ArrayList();
		while (m-- > 0) {
			int u = sc.nextInt() - 1, v = sc.nextInt() - 1, w = sc.nextInt();
			adj[u].add(new int[] { v, w });
			adj[v].add(new int[] { u, w });

		}
		long[] ans = solve();
		for (long x : ans) {
			if (x == INF)
				out.print(-1 + " ");
			else
				out.print(x + " ");
		}
		out.println();
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready() || st.hasMoreTokens();
		}

		int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}