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.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class PairedPayment implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    read();
    dijkstra();
    for (int i = 0; i < n; i++) {
      out.print(dist[i] == oo ? -1 : dist[i]);
      out.print(' ');
    }
  }

  private void read() {
    n = in.ni();
    m = in.ni();
    graph = new ArrayList<>();
    for (int i = 0; i <= n; i++) {
      graph.add(new ArrayList<>());
    }
    for (int i = 0; i < m; i++) {
      int from = in.ni() - 1, to = in.ni() - 1;
      long weight = in.nl();
      graph.get(from).add(new Edge(to, weight));
      graph.get(to).add(new Edge(from, weight));
    }
    dist = new long[n];
    for (int i = 0; i < n; i++) {
      dist[i] = oo;
    }
  }

  private final long oo = (long) 1e16;
  private int n, m;
  private long[] dist;
  private List<List<Edge>> graph;

  private class Edge {
    private int to;
    private long cost;

    private Edge(int to, long cost) {
      this.to = to;
      this.cost = cost;
    }

    public long getCost() {
      return cost;
    }
  }

  private void dijkstra() {
    PriorityQueue<Edge> queue = new PriorityQueue<>(Comparator.comparingLong(Edge::getCost));
    queue.add(new Edge(0, 0));
    dist[0] = 0;
    while (queue.size() > 0) {
      Edge top = queue.poll();
      int u = top.to;
      for (Edge first : graph.get(u)) {
        long wa = first.cost;
        for (Edge second : graph.get(first.to)) {
          long wb = second.cost;
          int v = second.to;
          long relax = dist[u] + (wa + wb) * (wa + wb);
          if (relax < dist[v]) {
            queue.add(new Edge(v, relax));
            dist[v] = relax;
          }
        }
      }
    }
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 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 ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (PairedPayment instance = new PairedPayment()) {
      instance.solve();
    }
  }
}
