#include <bits/stdc++.h>
using namespace std;
const int N = 100008;
const int M = 1000000000;
vector<int> a[N];
int n, m, fa[N], recf[N * 10], ans[N * 10];
pair<pair<int, int>, int> rec[N * 10];
priority_queue<pair<int, int> > e;
int mf[N][17], ma[N][17], mi[N][17], dep[N];
int findr(int x) {
  if (fa[x]) return fa[x] = findr(fa[x]);
  return x;
}
int maxx(int x, int y) {
  if (x > y) y = x;
  return y;
}
int minx(int x, int y) {
  if (x < y) y = x;
  return y;
}
int dfs(int x, int y) {
  dep[x] = dep[y] + 1;
  for (auto p : a[x])
    if (p != y) dfs(p, x);
  return 0;
}
int main(void) {
  int i, j, k, p1, p2, p3;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &p1, &p2, &p3);
    e.push(make_pair(-p3, i));
    rec[i] = make_pair(make_pair(p1, p2), p3);
  }
  k = n - 1;
  while (k && !e.empty()) {
    auto p = e.top();
    e.pop();
    p1 = findr(rec[p.second].first.first);
    p2 = findr(rec[p.second].first.second);
    if (p1 != p2) {
      k--;
      fa[p1] = p2;
      recf[p.second] = 1;
      a[rec[p.second].first.first].push_back(rec[p.second].first.second);
      a[rec[p.second].first.second].push_back(rec[p.second].first.first);
    }
  }
  dfs(1, 0);
  for (i = 1; i <= m; i++)
    if (recf[i]) {
      p1 = (dep[rec[i].first.first] < dep[rec[i].first.second]
                ? rec[i].first.second
                : rec[i].first.first);
      p2 = rec[i].first.first + rec[i].first.second - p1;
      mf[p1][0] = p2;
      ma[p1][0] = rec[i].second;
    }
  for (i = 0; i <= 16; i++)
    for (j = 0; j <= n; j++) mi[j][i] = M;
  for (i = 1; i <= 16; i++)
    for (j = 1; j <= n; j++) {
      mf[j][i] = mf[mf[j][i - 1]][i - 1];
      ma[j][i] = maxx(ma[j][i - 1], ma[mf[j][i - 1]][i - 1]);
    }
  for (i = 1; i <= m; i++)
    if (recf[i] == 0) {
      p1 = rec[i].first.first;
      p2 = rec[i].first.second;
      if (dep[p1] > dep[p2]) {
        k = p1;
        p1 = p2;
        p2 = k;
      }
      k = 16;
      while (dep[p1] < dep[p2]) {
        while (k >= 0 && dep[p1] > dep[p2] - (1 << k)) k--;
        ans[i] = maxx(ans[i], ma[p2][k]);
        mi[p2][k] = minx(mi[p2][k], rec[i].second);
        p2 = mf[p2][k];
      }
      k = 16;
      while (mf[p1][0] != mf[p2][0]) {
        while (k >= 0 && mf[p1][k] == mf[p2][k]) k--;
        if (k >= 0) {
          ans[i] = maxx(ans[i], maxx(ma[p1][k], ma[p2][k]));
          mi[p1][k] = minx(mi[p1][k], rec[i].second);
          mi[p2][k] = minx(mi[p2][k], rec[i].second);
          p1 = mf[p1][k];
          p2 = mf[p2][k];
        }
      }
      if (p1 != p2) {
        ans[i] = maxx(ans[i], maxx(ma[p1][0], ma[p2][0]));
        mi[p1][0] = minx(mi[p1][0], rec[i].second);
        mi[p2][0] = minx(mi[p2][0], rec[i].second);
      }
    }
  for (i = 16; i >= 1; i--)
    for (j = 1; j <= n; j++) {
      mi[j][i - 1] = minx(mi[j][i - 1], mi[j][i]);
      mi[mf[j][i - 1]][i - 1] = minx(mi[mf[j][i - 1]][i - 1], mi[j][i]);
    }
  for (i = 1; i <= m; i++)
    if (recf[i]) {
      p1 = (dep[rec[i].first.first] < dep[rec[i].first.second]
                ? rec[i].first.second
                : rec[i].first.first);
      ans[i] = mi[p1][0];
    }
  for (i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
