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>
using namespace std;
int n, m, num = 0, mx = 0, f[200010], fa[200010][20], st[200010][20],
          ans[200010], val[200010], h[200010], flag[200010], d[200010];
struct node {
  int x, y, z, id;
} a[200010];
struct edge {
  int x, y, z, next;
} mp[200010 << 1];
inline char gc() {
  static char *S, *T, buf[1 << 16];
  if (T == S) {
    T = (S = buf) + fread(buf, 1, 1 << 16, stdin);
    if (T == S) return EOF;
  }
  return *S++;
}
inline int read() {
  int x = 0, f = 1;
  char ch = gc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = gc();
  }
  while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = gc();
  return x * f;
}
int find(int x) {
  if (f[x] != x) f[x] = find(f[x]);
  return f[x];
}
inline void ins(int x, int y, int z) {
  mp[++num].x = x;
  mp[num].y = y;
  mp[num].z = z;
  mp[num].next = h[x];
  h[x] = num;
  mp[++num].x = y;
  mp[num].y = x;
  mp[num].z = z;
  mp[num].next = h[y];
  h[y] = num;
}
inline bool cmp(node x, node y) { return x.z < y.z; }
inline void kruskal() {
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = find(a[i].x), y = find(a[i].y);
    if (x == y) continue;
    f[x] = y;
    flag[i] = 1;
    ins(a[i].x, a[i].y, a[i].z);
  }
}
void dfs(int x) {
  for (int i = 1; i <= 18; i++) {
    if (!fa[x][i - 1]) break;
    fa[x][i] = fa[fa[x][i - 1]][i - 1];
    st[x][i] = max(st[x][i - 1], st[fa[x][i - 1]][i - 1]);
  }
  for (int i = h[x]; i; i = mp[i].next) {
    int y = mp[i].y;
    if (y == fa[x][0]) continue;
    fa[y][0] = x;
    st[y][0] = mp[i].z;
    d[y] = d[x] + 1;
    dfs(y);
  }
}
inline int lca(int x, int y) {
  mx = 0;
  if (d[x] < d[y]) swap(x, y);
  int len = d[x] - d[y];
  for (int i = 0; i <= 18; i++) {
    if (len & (1 << i)) mx = max(mx, st[x][i]), x = fa[x][i];
  }
  if (x == y) return x;
  for (int i = 18; i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) {
      mx = max(mx, max(st[x][i], st[y][i]));
      x = fa[x][i], y = fa[y][i];
    }
  }
  mx = max(mx, max(st[x][0], st[y][0]));
  return fa[x][0];
}
inline void merge(int x, int y, int z) {
  x = find(x);
  while (d[x] > d[y]) {
    val[x] = z;
    x = f[x] = find(fa[x][0]);
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++)
    a[i].x = read(), a[i].y = read(), a[i].z = read(), a[i].id = i;
  kruskal();
  dfs(1);
  for (int i = 1; i <= n; i++) f[i] = i, val[i] = 0x3f3f3f3f;
  for (int i = 1; i <= m; i++) {
    if (!flag[i]) {
      int x = a[i].x, y = a[i].y, z = lca(x, y);
      ans[a[i].id] = mx - 1;
      merge(x, z, a[i].z);
      merge(y, z, a[i].z);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (flag[i]) {
      int x = a[i].x, y = a[i].y;
      if (d[x] < d[y]) x = y;
      ans[a[i].id] = val[x] - 1;
    }
  }
  for (int i = 1; i <= m; i++)
    printf("%d ", ans[i] == 0x3f3f3f3f - 1 ? -1 : ans[i]);
  return 0;
}
