You are given a connected weighted graph with n vertices and m edges. The graph doesn't contain loops nor multiple edges. Consider some edge with id i. Let's determine for this edge the maximum integer weight we can give to it so that it is contained in all minimum spanning trees of the graph if we don't change the other weights.

You are to determine this maximum weight described above for each edge. You should calculate the answer for each edge independently, it means there can't be two edges with changed weights at the same time.

Input

The first line contains two integers n and m (2 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105), where n and m are the number of vertices and the number of edges in the graph, respectively.

Each of the next m lines contains three integers u, v and c (1 ≤ v, u ≤ n, v ≠ u, 1 ≤ c ≤ 109) meaning that there is an edge between vertices u and v with weight c. 

Output

Print the answer for each edge in the order the edges are given in the input. If an edge is contained in every minimum spanning tree with any weight, print -1 as the answer.

Examples

Input

4 4
1 2 2
2 3 2
3 4 2
4 1 3


Output

2 2 2 1 

Input

4 3
1 2 2
2 3 2
3 4 2


Output

-1 -1 -1 
#include <bits/stdc++.h>
template <class T>
inline void readin(T &res) {
  static char ch;
  T flag = 1;
  while ((ch = getchar()) < '0' || ch > '9')
    if (ch == '-') flag = -1;
  res = ch - 48;
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - 48;
  res *= flag;
}
const int N = 200000 + 100;
const int M = 200000 + 100;
int n, m;
struct EDGE {
  int v, upre;
} g[M << 1];
int head[N], ne = 0;
inline void adde(int u, int v) {
  g[++ne] = (EDGE){v, head[u]};
  head[u] = ne;
}
struct edgement {
  int u, v, w, tag, id;
} edge[M];
inline bool cmpw(edgement a, edgement b) { return a.w < b.w; }
inline bool cmpid(edgement a, edgement b) { return a.id < b.id; }
int f[N], s[N];
inline int find(int x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
inline void unoin(int u, int v) {
  u = find(u), v = find(v);
  if (s[u] > s[v])
    s[u] += s[v], f[v] = u;
  else
    s[v] += s[u], f[u] = v;
}
void KRUSKAL() {
  for (int i = 1; i <= n; i++) f[i] = i, s[i] = 1;
  std::sort(edge + 1, edge + m + 1, cmpw);
  for (int i = 1, u, v; i <= m; i++) {
    u = edge[i].u, v = edge[i].v;
    if (find(u) != find(v))
      edge[i].tag = 1, adde(u, v), adde(v, u), unoin(u, v);
  }
}
int siz[N], fa[N], dep[N], son[N];
void DFS1(int u) {
  siz[u] = 1;
  for (int i = head[u], v; i; i = g[i].upre) {
    if ((v = g[i].v) == fa[u]) continue;
    fa[v] = u;
    dep[v] = dep[u] + 1;
    DFS1(v);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
}
int top[N], in[N], seq[N], idy;
void DFS2(int u, int tp) {
  in[u] = ++idy;
  top[u] = tp;
  if (son[u]) DFS2(son[u], tp);
  for (int i = head[u], v; i; i = g[i].upre) {
    if ((v = g[i].v) == son[u] || v == fa[u]) continue;
    DFS2(v, v);
  }
}
void smin(int &a, int b) { a = std::min(a, b); }
struct NODE {
  int bound, vmax;
  NODE *ls, *rs;
} pool[N << 1], *tail = pool, *root;
NODE *build(int lf, int rg) {
  NODE *nd = tail++;
  nd->bound = 0x3f3f3f3f;
  if (lf == rg) {
    nd->vmax = edge[seq[lf]].w;
    return nd;
  }
  int mid = (lf + rg) >> 1;
  nd->ls = build(lf, mid);
  nd->rs = build(mid + 1, rg);
  nd->vmax = std::max(nd->ls->vmax, nd->rs->vmax);
  return nd;
}
void query_bound(NODE *nd, int lf, int rg, int bound) {
  smin(bound, nd->bound);
  if (lf == rg) {
    edge[seq[lf]].tag = bound;
    return;
  }
  int mid = (lf + rg) >> 1;
  query_bound(nd->ls, lf, mid, bound);
  query_bound(nd->rs, mid + 1, rg, bound);
}
int query_modify(NODE *nd, int lf, int rg, int L, int R, int bound) {
  if (L <= lf && rg <= R) {
    smin(nd->bound, bound);
    return nd->vmax;
  }
  int mid = (lf + rg) >> 1, td = 0;
  if (L <= mid) td = std::max(td, query_modify(nd->ls, lf, mid, L, R, bound));
  if (mid < R)
    td = std::max(td, query_modify(nd->rs, mid + 1, rg, L, R, bound));
  return td;
}
int querymax(int u, int v, int w) {
  int ans = 0;
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) std::swap(u, v);
    ans = std::max(ans, query_modify(root, 1, n, in[top[u]], in[u], w));
    u = fa[top[u]];
  }
  if (dep[u] < dep[v]) std::swap(u, v);
  ans = std::max(ans, query_modify(root, 1, n, in[son[v]], in[u], w));
  return ans;
}
int main() {
  memset(head, 0, sizeof(head));
  memset(son, 0, sizeof(son));
  siz[0] = 0;
  idy = 0;
  readin(n);
  readin(m);
  for (int i = 1, u, v, w; i <= m; i++) {
    readin(u), readin(v), readin(w);
    edge[i] = (edgement){u, v, w, 0, i};
  }
  KRUSKAL();
  fa[1] = 1;
  dep[1] = 1;
  DFS1(1);
  DFS2(1, 1);
  for (int i = 1, u, v; i <= m; i++)
    if (edge[i].tag) {
      u = edge[i].u, v = edge[i].v;
      if (dep[u] < dep[v]) std::swap(u, v);
      seq[in[u]] = i;
    }
  root = build(1, n);
  for (int i = 1; i <= m; i++)
    if (!edge[i].tag) edge[i].tag = querymax(edge[i].u, edge[i].v, edge[i].w);
  query_bound(root, 1, n, 0x3f3f3f3f);
  std::sort(edge + 1, edge + m + 1, cmpid);
  for (int i = 1; i <= m; i++)
    printf("%d%c", edge[i].tag != 0x3f3f3f3f ? edge[i].tag - 1 : -1,
           i != m ? ' ' : '\n');
  return 0;
}
