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>
//stan hu tao
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;

public class x1486E
{
    static final long INF = (Long.MAX_VALUE-420)/3;
    static ArrayDeque<Edge>[] edges;
    public static void main(String hi[]) throws Exception
    {
        FastScanner infile = new FastScanner();
        int N = infile.nextInt();
        int M = infile.nextInt();
        edges = new ArrayDeque[N];
        for(int i=0; i < N; i++)
            edges[i] = new ArrayDeque<Edge>();
        while(M-->0)
        {
            int u = infile.nextInt()-1;
            int v = infile.nextInt()-1;
            int w = infile.nextInt();
            edges[u].add(new Edge(v, w));
            edges[v].add(new Edge(u, w));
        }
        long[][] dp = new long[N][51];
        for(int i=0; i < N; i++)
            Arrays.fill(dp[i], INF);
        boolean[][] seen = new boolean[N][51];
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(0, 0, 0L));
        dp[0][0] = 0L;
        while(pq.size() > 0)
        {
            Node curr = pq.poll();
            if(seen[curr.id][curr.tag])
                continue;
            seen[curr.id][curr.tag] = true;
            for(Edge e: edges[curr.id])
            {
                if(curr.tag == 0)
                {
                    if(dp[e.to][e.weight] > curr.dist)
                    {
                        dp[e.to][e.weight] = curr.dist;
                        pq.add(new Node(e.to, e.weight, curr.dist));
                    }
                }
                else
                {
                    int add = (e.weight+curr.tag)*(e.weight+curr.tag);
                    if(dp[e.to][0] > curr.dist+add)
                    {
                        dp[e.to][0] = curr.dist+add;
                        pq.add(new Node(e.to, 0, curr.dist+add));
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int v=0; v < N; v++)
        {
            if(dp[v][0] == INF)
                dp[v][0] = -1;
            sb.append(dp[v][0]+" ");
        }
        System.out.println(sb);
    }
}
class Node implements Comparable<Node>
{
    public int id;
    public int tag;
    public long dist;

    public Node(int a, int b, long d)
    {
        id = a;
        tag = b;
        dist = d;
    }
    public int compareTo(Node oth)
    {
        return Long.compare(dist, oth.dist);
    }
}
class Edge
{
    public int to;
    public int weight;

    public Edge(int a, int b)
    {
        to = a;
        weight = b;
    }
}
class FastScanner
{
    private int BS = 1 << 16;
    private char NC = (char) 0;
    private byte[] buf = new byte[BS];
    private int bId = 0, size = 0;
    private char c = NC;
    private double cnt = 1;
    private BufferedInputStream in;

    public FastScanner() {
        in = new BufferedInputStream(System.in, BS);
    }

    public FastScanner(String s) {
        try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
        }
    }

    private char getChar() {
        while (bId == size) {
            try {
                size = in.read(buf);
            } catch (Exception e) {
                return NC;
            }
            if (size == -1) return NC;
            bId = 0;
        }
        return (char) buf[bId++];
    }

    public int nextInt() {
        return (int) nextLong();
    }

    public int[] nextInts(int N) {
        int[] res = new int[N];
        for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
        }
        return res;
    }

    public long[] nextLongs(int N) {
        long[] res = new long[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextLong();
        }
        return res;
    }

    public long nextLong() {
        cnt = 1;
        boolean neg = false;
        if (c == NC) c = getChar();
        for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
        }
        long res = 0;
        for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
        }
        return neg ? -res : res;
    }

    public double nextDouble() {
        double cur = nextLong();
        return c != '.' ? cur : cur + nextLong() / cnt;
    }

    public double[] nextDoubles(int N) {
        double[] res = new double[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
        }
        return res;
    }

    public String next() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c > 32) {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public String nextLine() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c != '\n') {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public boolean hasNext() {
        if (c > 32) return true;
        while (true) {
            c = getChar();
            if (c == NC) return false;
            else if (c > 32) return true;
        }
    }
}