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.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
 import java.util.*;
 public class realfast implements Runnable 
  {
    private static final int INF = (int) 1e9;
    long in= 1000000007;
    long fac[]= new long[1000001];
    long inv[]=new long[1000001];
    public  void solve() throws IOException 
    {

        //int t = readInt();


         int n = readInt();
         int m = readInt();
         ArrayList<edge> adj[]=new ArrayList[n+1];
         for(int i =0;i<=n;i++)
            adj[i]= new ArrayList<edge>();
         long dist[][]=new long[n+1][51];
        long inf =0;
         for(int i =0;i<=n;i++)
         {
            for(int j=0;j<=50;j++)
            {
                dist[i][j]=2000000000;
                dist[i][j]= dist[i][j]*10;
                inf=dist[i][j];
            }
         }
         
         boolean visited[][]=new boolean[n+1][51];

         for(int i =0;i<m;i++)
         {
            int u = readInt();
            int v = readInt();
            int w = readInt();
            adj[u].add(new edge(v,0,w));
            adj[v].add(new edge(u,0,w));
         }

         PriorityQueue<edge> h = new PriorityQueue<edge>();

        

         dist[1][0]=0;

         h.add(new edge(1,0,0));


         while(h.size()!=0)
         {

            edge lo = h.poll();

            int cur= lo.u;
            int s = lo.state;
            long dist1 = lo.dist;
            if(visited[cur][s])
                continue;

             visited[cur][s]= true;

             if(s==0)
             {
                 for(int j =0;j<adj[cur].size();j++)
                 {
                    int v = adj[cur].get(j).u;
                    int dl= (int)adj[cur].get(j).dist;
                    if(!visited[v][dl]&&(dl*dl)+dist1<dist[v][dl])
                    {
                        dist[v][dl]= (dl*dl)+dist1;
                        h.add(new edge(v,dl,dist[v][dl]));
                    }
                 }

             }
             else
             {
                for(int j =0;j<adj[cur].size();j++)
                 {
                    int v = adj[cur].get(j).u;
                    int dl= (int)adj[cur].get(j).dist;
                    if(!visited[v][0]&&((dl*dl)+dist1+2*dl*s<dist[v][0]))
                    {
                        dist[v][0]= (dl*dl)+dist1+2*dl*s;
                        h.add(new edge(v,0,dist[v][0]));
                    }
                 }

             }

         }
         
         for(int i =1;i<=n;i++)
         {
               if(dist[i][0]<inf)
                out.print(dist[i][0]+" ");
                else
                out.print((-1)+" ");
         }

         






        
      

    }
    
    public int value (int seg[], int left , int right ,int index, int l, int r)
    {
            
            if(left>right)
            {
              return -100000000;
            }
            if(right<l||left>r)
                return -100000000;
            if(left>=l&&right<=r)
                return seg[index];
            int mid = left+(right-left)/2;
            int val = value(seg,left,mid,2*index+1,l,r);
            int val2 = value(seg,mid+1,right,2*index+2,l,r);
            return Math.max(val,val2);

    }
   
    public int gcd(int a , int b )
    {
      if(a<b)
      {
        int t =a;
        a=b;
        b=t;
      }
      if(a%b==0)
        return b ;
      return gcd(b,a%b);
    }
    public long pow(long n , long p,long m)
    {
         if(p==0)
            return 1;
        long val = pow(n,p/2,m);;
        val= (val*val)%m;
        if(p%2==0)
            return val;
        else
            return (val*n)%m;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
    }
 
    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;
 
    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }
 
    private String readString() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
 
    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
 
    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }
 
    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class edge implements Comparable<edge>{
    int u;
    int state;
    long dist;
    
    edge(int u, int state, long dist)
    {
       this.u=u;
       this.state=state;
       this.dist= dist;
    }
    public int compareTo(edge e)
    {
        if(this.dist-e.dist>0)
            return 1;
        else if(this.dist==e.dist)
            return 0;
        else
            return -1;
    }
}