#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 1e6 + 5;
struct edge {
  int u, v, w, id, fl;
} a[M];
vector<vector<int>> e[N];
int dep[N], mx[N][20], fa[N][20], num[N];
void dfs(int u, int fath) {
  dep[u] = dep[fath] + 1;
  fa[u][0] = fath;
  for (int i = 1; i < 20; ++i)
    fa[u][i] = fa[fa[u][i - 1]][i - 1],
    mx[u][i] = max(mx[u][i - 1], mx[fa[u][i - 1]][i - 1]);
  for (auto p : e[u])
    if (p[0] != fath) mx[p[0]][0] = p[1], num[p[0]] = p[2], dfs(p[0], u);
}
pair<int, int> lca(int u, int v) {
  int ans = 0;
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; i >= 0; --i)
    if (dep[fa[u][i]] >= dep[v]) ans = max(ans, mx[u][i]), u = fa[u][i];
  if (u == v) return {u, ans};
  for (int i = 19; i >= 0; --i)
    if (fa[u][i] != fa[v][i])
      ans = max({ans, mx[u][i], mx[v][i]}), u = fa[u][i], v = fa[v][i];
  return {fa[u][0], max({ans, mx[u][0], mx[v][0]})};
}
int ans[M], f[N];
int find(int x) { return x == f[x] ? f[x] : f[x] = find(f[x]); }
signed main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) cin >> a[i].u >> a[i].v >> a[i].w, a[i].id = i;
  sort(a + 1, a + m + 1, [](edge i, edge j) { return i.w < j.w; });
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= m; ++i) {
    int x = find(a[i].u), y = find(a[i].v);
    if (x == y) continue;
    f[x] = y;
    a[i].fl = 1;
    e[a[i].u].push_back({a[i].v, a[i].w, a[i].id}),
        e[a[i].v].push_back({a[i].u, a[i].w, a[i].id});
  }
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= m; ++i)
    if (a[i].fl == 1) ans[a[i].id] = 1e9;
  for (int i = 1; i <= m; ++i) {
    auto p = lca(a[i].u, a[i].v);
    if (a[i].fl == 0) {
      ans[a[i].id] = p.second;
      int x = find(a[i].u), y = find(a[i].v);
      while (dep[x] > dep[p.first]) {
        if (num[x]) ans[num[x]] = a[i].w;
        f[x] = find(fa[x][0]);
        x = find(x);
      }
      while (dep[y] > dep[p.first]) {
        if (num[y]) ans[num[y]] = a[i].w;
        f[y] = find(fa[y][0]), y = find(y);
      }
    }
  }
  for (int i = 1; i <= m; ++i) cout << ans[i] << "\n";
}
