#include <bits/stdc++.h>
using namespace std;
int n, m, p, q, cnt, ans, f[100010], fv[100010], id[100010], son[100010],
    su[100010], fa[100010], tp[100010], w[100010], de[100010];
int x1[2 * 100010], r[2 * 100010], vt[2 * 100010], v[2 * 100010], cnt1;
int an[10 * 100010];
bool pi[10 * 100010];
void adde(int a, int b, int k) {
  r[++cnt] = x1[a];
  x1[a] = cnt;
  vt[cnt] = b;
  v[cnt] = k;
  r[++cnt] = x1[b];
  x1[b] = cnt;
  vt[cnt] = a;
  v[cnt] = k;
}
struct seg {
  int v[4 * 100010], v2[4 * 100010], lz[4 * 100010];
  void pd(int i) {
    if (lz[i] < 1e9) {
      v2[i * 2] = min(v2[i * 2], lz[i]);
      v2[i * 2 + 1] = min(v2[i * 2 + 1], lz[i]);
      lz[i * 2] = min(lz[i * 2], lz[i]);
      lz[i * 2 + 1] = min(lz[i * 2 + 1], lz[i]);
      lz[i] = 1e9;
    }
  }
  void bu(int i, int l, int r) {
    lz[i] = v2[i] = 1e9;
    if (l == r) {
      v[i] = w[fv[l]];
      return;
    }
    bu(i * 2, l, (l + r) / 2);
    bu(i * 2 + 1, (l + r) / 2 + 1, r);
    v[i] = max(v[i * 2], v[i * 2 + 1]);
  }
  int qy(int i, int l, int r, int ql, int qr) {
    if (ql > r || l > qr) return 0;
    if (ql <= l && r <= qr) return v[i];
    pd(i);
    return max(qy(i * 2, l, (l + r) / 2, ql, qr),
               qy(i * 2 + 1, (l + r) / 2 + 1, r, ql, qr));
  }
  int qy2(int i, int l, int r, int k) {
    if (l == r) return v2[i];
    pd(i);
    int mi = (l + r) / 2;
    if (k <= mi) return qy2(i * 2, l, mi, k);
    return qy2(i * 2 + 1, mi + 1, r, k);
  }
  void mdf(int i, int l, int r, int ql, int qr, int k) {
    if (ql > r || l > qr) return;
    if (ql <= l && r <= qr) {
      v2[i] = min(v2[i], k);
      lz[i] = min(lz[i], k);
      return;
    }
    pd(i);
    mdf(i * 2, l, (l + r) / 2, ql, qr, k);
    mdf(i * 2 + 1, (l + r) / 2 + 1, r, ql, qr, k);
    v2[i] = min(v2[i * 2], v2[i * 2 + 1]);
  }
} tr, tr2;
int ff(int a) {
  if (f[a] == a) return a;
  return f[a] = ff(f[a]);
}
struct node {
  int a, b, w, id;
  bool operator<(node const &a) const { return w < a.w; }
} e[10 * 100010];
void dfs1(int i) {
  int s, a, b, j, k;
  a = x1[i];
  su[i] = 1;
  j = 0;
  while (a) {
    b = vt[a];
    if (b != fa[i]) {
      de[b] = de[i] + 1;
      fa[b] = i;
      w[b] = v[a];
      dfs1(b);
      su[i] += su[b];
      if (su[b] > j) j = su[b], son[i] = b;
    }
    a = r[a];
  }
}
void dfs2(int i, int tt) {
  int s, a, b, j, k;
  a = x1[i];
  tp[i] = tt;
  fv[id[i] = ++cnt1] = i;
  if (son[i]) dfs2(son[i], tt);
  while (a) {
    b = vt[a];
    if (!id[b]) dfs2(b, b);
    a = r[a];
  }
}
int cal(int a, int b) {
  int ans1 = 0;
  while (tp[a] != tp[b]) {
    if (de[tp[a]] > de[tp[b]]) swap(a, b);
    ans1 = max(ans1, tr.qy(1, 1, n, id[tp[b]], id[b]));
    b = fa[tp[b]];
  }
  if (de[a] > de[b]) swap(a, b);
  ans1 = max(ans1, tr.qy(1, 1, n, id[a] + 1, id[b]));
  return ans1;
}
void work(int a, int b, int k) {
  while (tp[a] != tp[b]) {
    if (de[tp[a]] > de[tp[b]]) swap(a, b);
    tr2.mdf(1, 1, n, id[tp[b]], id[b], k);
    b = fa[tp[b]];
  }
  if (de[a] > de[b]) swap(a, b);
  tr2.mdf(1, 1, n, id[a] + 1, id[b], k);
}
int main() {
  int i, s, a, b, j, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++)
    scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].w), e[i].id = i, an[i] = -1;
  sort(e + 1, e + 1 + m);
  for (i = 1; i <= n; i++) f[i] = i;
  for (i = 1; i <= m; i++) {
    a = ff(e[i].a);
    b = ff(e[i].b);
    if (a != b) {
      pi[i] = 1;
      f[a] = b;
      adde(e[i].a, e[i].b, e[i].w);
    }
  }
  dfs1(fa[1] = de[1] = 1);
  dfs2(1, 1);
  tr.bu(1, 1, n);
  tr2.bu(1, 1, n);
  for (i = 1; i <= m; i++)
    if (!pi[i]) an[e[i].id] = cal(e[i].a, e[i].b), work(e[i].a, e[i].b, e[i].w);
  for (i = 1; i <= m; i++)
    if (pi[i]) {
      a = e[i].a;
      b = e[i].b;
      if (de[a] < de[b]) swap(a, b);
      an[e[i].id] = tr2.qy2(1, 1, n, id[a]);
    }
  for (i = 1; i <= m; i++) printf("%d\n", an[i]);
  return 0;
}
