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.awt.geom.AffineTransform;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {

		int n=sc.nextInt();
		int m=sc.nextInt();
		ArrayList<pair>[]gr=new ArrayList[n];
		for(int i=0;i<n;i++)gr[i]=new ArrayList<pair>();
		for(int i=0;i<m;i++) {
			int x=sc.nextInt()-1;
			int y=sc.nextInt()-1;
			int v=sc.nextInt();
			gr[x].add(new pair(y, v));
			gr[y].add(new pair(x, v));
		}
		PriorityQueue<tuble>pq=new PriorityQueue<Main.tuble>();
	
		Integer[][]ans=new Integer[n][51];
		Integer[][]dist=new Integer[n][51];
		dist[0][0]=0;
		pq.add(new tuble(0, 0, 0));
		while(!pq.isEmpty()) {
//			pw.println(pq);
			tuble z =pq.poll();
			if(ans[(int) z.z][(int) z.y]==null) {
				ans[(int) z.z][(int) z.y]=(int) (z.x);
//				pw.println(z);
				for(pair i:gr[(int) z.z]) {
					
					if(z.y==0) {
						if(dist[(int) i.x][(int) i.y]==null||dist[(int) i.x][(int) i.y]>(z.x+i.y)) {
							dist[(int) i.x][(int) i.y]=(int) (z.x+i.y);
							pq.add(new tuble(z.x+i.y, i.y, i.x));
						}
					}else {
						if(dist[(int) i.x][0]==null||dist[(int) i.x][0]>(z.x-z.y+(i.y+z.y)*(i.y+z.y))) {
							dist[(int) i.x][0]=(int) (z.x-z.y+(i.y+z.y)*(i.y+z.y));
						pq.add(new tuble(z.x-z.y+(i.y+z.y)*(i.y+z.y), 0, i.x));
						}
					}
				}
			}
		}
		for(int i=0;i<n;i++) {
			if(ans[i][0]==null) {
				pw.print(-1+" ");
			}else {
				pw.print(ans[i][0]+" ");
			}
		}
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

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

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

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

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

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

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

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

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

	}

	static class pair implements Comparable<pair> {
		long x;
		long y;

		public pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	static class tuble implements Comparable<tuble> {
		long x;
		long y;
		long z;

		public tuble(long x, long y, long z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y) {
					return Long.compare(this.z , other.z);
				}
				return Long.compare(this.y , other.y);
			} else {
				return Long.compare(this.x , other.x);
			}
		}
	}

	static long mod = 1000000007;
	static Random rn = new Random();
	static Scanner sc = new Scanner(System.in);
	static PrintWriter pw = new PrintWriter(System.out);
}