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;
const int Maxn = 2e5 + 5;
const int INF = 1e9 + 5;
class edge {
 public:
  int u, v, c, id;
  void read(int i) {
    scanf("%d%d%d", &u, &v, &c);
    id = i;
  }
  bool operator<(const edge& o) const { return c < o.c; }
};
int n, m;
edge e[Maxn];
int ans[Maxn];
int pa[Maxn];
int dep[Maxn];
int maxw[Maxn][19];
int ancs[Maxn][19];
bool marked[Maxn];
int up[Maxn];
int minw[Maxn];
vector<pair<int, int> > adj[Maxn];
bool used[Maxn];
int find(int x) { return (x == pa[x]) ? x : pa[x] = find(pa[x]); }
bool uni(edge edg) {
  int a = find(edg.u), b = find(edg.v);
  if (a == b) return false;
  pa[b] = a;
  return true;
}
void mst() {
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; i++) {
    if (uni(e[i])) {
      adj[e[i].u].push_back(pair<int, int>(e[i].v, e[i].c));
      adj[e[i].v].push_back(pair<int, int>(e[i].u, e[i].c));
      used[i] = true;
    }
  }
}
void dfs(int now, int pre = -1) {
  for (auto v : adj[now]) {
    if (v.first != pre) {
      dep[v.first] = dep[now] + 1;
      ancs[v.first][0] = now;
      maxw[v.first][0] = v.second;
      for (int i = 1; i <= 18; i++) {
        ancs[v.first][i] = ancs[ancs[v.first][i - 1]][i - 1];
        maxw[v.first][i] =
            max(maxw[v.first][i - 1], maxw[ancs[v.first][i - 1]][i - 1]);
      }
      up[v.first] = now;
      dfs(v.first, now);
    }
  }
}
void build() {
  dep[1] = 0;
  for (int i = 0; i <= 18; i++) {
    ancs[1][i] = 1;
    maxw[1][i] = 0;
  }
  dfs(1);
  memset(minw, 0, sizeof minw);
  memset(marked, 0, sizeof marked);
}
int mark(int src, int dst, int wgt) {
  if (dep[src] <= dep[dst]) return src;
  if (!marked[src]) {
    marked[src] = true;
    minw[src] = wgt;
  }
  return up[src] = mark(up[src], dst, wgt);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) pa[i] = i;
  for (int i = 1; i <= m; i++) {
    e[i].read(i);
  }
  mst();
  build();
  for (int i = 1; i <= m; i++) {
    if (!used[i]) {
      int u = e[i].u, v = e[i].v;
      if (dep[u] < dep[v]) swap(u, v);
      int w = 0;
      for (int i = 18; i >= 0; i--) {
        if ((1 << i) <= dep[u] - dep[v]) {
          w = max(w, maxw[u][i]);
          u = ancs[u][i];
        }
      }
      for (int i = 18; i >= 0; i--) {
        if (ancs[u][i] != ancs[v][i]) {
          w = max(w, maxw[u][i]);
          w = max(w, maxw[v][i]);
          u = ancs[u][i];
          v = ancs[v][i];
        }
      }
      int lca = u;
      if (u != v) {
        w = max(w, maxw[u][0]);
        w = max(w, maxw[v][0]);
        lca = ancs[u][0];
      }
      ans[e[i].id] = w - 1;
      u = e[i].u;
      v = e[i].v;
      mark(u, lca, e[i].c);
      mark(v, lca, e[i].c);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (used[i]) {
      int u = e[i].u, v = e[i].v;
      if (dep[u] < dep[v]) swap(u, v);
      ans[e[i].id] = minw[u] - 1;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d ", ans[i]);
  return 0;
}
