With your help, Heidi has prepared a plan of trap placement and defence. Yet suddenly, the Doctor popped out of the TARDIS and told her that he had spied on the Daleks' preparations, and there is more of them than ever. Desperate times require desperate measures, so Heidi is going to risk meeting with the Daleks and she will consider placing a trap along any Corridor.

This means she needs your help again in calculating E_{max}(c) – the largest e ≤ 10^9 such that if we changed the energy requirement of c to e, then the Daleks might use c in their invasion – but this time for all Time Corridors.

Input

First line: number n of destinations, number m of corridors (2 ≤ n ≤ 10^5, n - 1 ≤ m ≤ 10^6). The next m lines: destinations a, b and energy e (1 ≤ a, b ≤ n, a ≠ b, 0 ≤ e ≤ 10^9).

No pair \\{a, b\} will repeat. The graph is guaranteed to be connected. It is not guaranteed that all energy requirements e are distinct, or that the minimum spanning tree is unique.

Output

Output m lines, each containing one integer: E_{max}(c_i) for the i-th Corridor c_i from the input.

Example

Input

3 3
1 2 8
2 3 3
3 1 4


Output

4
8
8
#include <bits/stdc++.h>
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int ii[1000000], jj[1000000], ww[1000000];
int compare_h(const void *a, const void *b) {
  int h1 = *(int *)a;
  int h2 = *(int *)b;
  return ww[h1] - ww[h2];
}
int dsu[100000];
int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); }
int join(int i, int j) {
  i = find(i);
  j = find(j);
  if (i == j) return 0;
  if (dsu[i] > dsu[j])
    dsu[i] = j;
  else {
    if (dsu[i] == dsu[j]) dsu[i]--;
    dsu[j] = i;
  }
  return 1;
}
int oo[1 + (100000 - 1) * 2], oh[1 + (100000 - 1) * 2];
int link(int o, int h) {
  static int _ = 1;
  oo[_] = o, oh[_] = h;
  return _++;
}
int ae[100000], dd[100000], ff[100000], pp[100000][16 + 1], ww_[100000][16 + 1],
    ta[100000], tb[100000];
void dfs(int f, int p, int i, int d) {
  static int time;
  int o, k;
  dd[i] = d, ff[i] = f;
  if (f != -1) {
    pp[i][0] = p;
    ww_[i][0] = ww[f];
    for (k = 1; 1 << k <= d; k++) {
      int q = pp[i][k - 1];
      pp[i][k] = pp[q][k - 1];
      ww_[i][k] = max(ww_[i][k - 1], ww_[q][k - 1]);
    }
  }
  ta[i] = time++;
  for (o = ae[i]; o; o = oo[o]) {
    int h = oh[o];
    if (h != f) {
      int j = i ^ ii[h] ^ jj[h];
      dfs(h, i, j, d + 1);
    }
  }
  tb[i] = time;
}
int query(int i, int j) {
  int k, w;
  if (dd[i] < dd[j]) return query(j, i);
  w = -1;
  for (k = 16; k >= 0; k--)
    if (dd[i] - dd[j] >= 1 << k) {
      w = max(w, ww_[i][k]);
      i = pp[i][k];
    }
  if (i == j) return w;
  for (k = 16; k >= 0; k--)
    if (dd[i] >= 1 << k && pp[i][k] != pp[j][k]) {
      w = max(w, max(ww_[i][k], ww_[j][k]));
      i = pp[i][k], j = pp[j][k];
    }
  w = max(w, max(ww_[i][0], ww_[j][0]));
  return w;
}
struct V {
  int h, l, r, w;
} vv[1000000];
int compare_V(const void *a, const void *b) {
  struct V *u = (struct V *)a;
  struct V *v = (struct V *)b;
  return u->l != v->l ? u->l - v->l : v->h - u->h;
}
int st[100000 * 2], n;
void pul(int i) { st[i] = min(st[i << 1], st[i << 1 | 1]); }
void st_update(int i, int x) {
  i += n;
  st[i] = min(st[i], x);
  while (i > 1) pul(i >>= 1);
}
int st_query(int l, int r) {
  int x = 0x3f3f3f3f;
  for (l += n, r += n; l <= r; l >>= 1, r >>= 1) {
    if ((l & 1) == 1) x = min(x, st[l++]);
    if ((r & 1) == 0) x = min(x, st[r--]);
  }
  return x;
}
int main() {
  static char tree[1000000];
  static int hh[1000000], ans[1000000];
  int m, m_, h, i, j, r;
  scanf("%d%d", &n, &m);
  for (h = 0; h < m; h++) {
    scanf("%d%d%d", &ii[h], &jj[h], &ww[h]), ii[h]--, jj[h]--;
    hh[h] = h;
  }
  qsort(hh, m, sizeof *hh, compare_h);
  memset(dsu, -1, n * sizeof *dsu);
  for (h = 0; h < m; h++) {
    int h_ = hh[h];
    i = ii[h_], j = jj[h_];
    if (join(i, j)) {
      tree[h_] = 1;
      ae[i] = link(ae[i], h_), ae[j] = link(ae[j], h_);
    }
  }
  dfs(-1, -1, 0, 0);
  m_ = 0;
  for (h = 0; h < m; h++)
    if (!tree[h]) {
      struct V *v;
      int tmp;
      i = ii[h], j = jj[h];
      ans[h] = query(i, j);
      if (ta[i] > ta[j]) tmp = i, i = j, j = tmp;
      v = &vv[m_++], v->h = -1, v->l = ta[i], v->r = ta[j], v->w = ww[h];
    } else
      ans[h] = 0x3f3f3f3f;
  for (i = 1; i < n; i++) {
    struct V *v;
    v = &vv[m_++], v->h = ff[i], v->l = ta[i], v->r = tb[i] - 1, v->w = -1;
  }
  for (r = 0; r < 2; r++) {
    qsort(vv, m, sizeof *vv, compare_V);
    memset(st, 0x3f, n * 2 * sizeof *st);
    for (h = 0; h < m; h++) {
      struct V *v = &vv[h];
      if (v->h == -1)
        st_update(v->r, v->w);
      else
        ans[v->h] = min(ans[v->h], st_query(v->l, v->r));
    }
    for (h = 0; h < m; h++) {
      struct V *v = &vv[h];
      int tmp;
      v->l = n - 1 - v->l, v->r = n - 1 - v->r;
      tmp = v->l, v->l = v->r, v->r = tmp;
    }
  }
  for (h = 0; h < m; h++)
    printf("%d\n", ans[h] == 0x3f3f3f3f ? 1000000000 : ans[h]);
  return 0;
}
