#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 1e6 + 6, inf = 1e9;
int n, m, p, ans[M], nxt[N << 1], head[N], to[N << 1], val[N << 1], ip[N << 1],
    f[N][22], mx[N][22], cnt, fa[N], dep[N], line[N];
struct edge {
  int u, v, w, i;
} E[M], e[M];
bool ok[M];
void addEdge(int u, int v, int w, int ID) {
  nxt[++cnt] = head[u], to[cnt] = v, head[u] = cnt, val[cnt] = w, ip[cnt] = ID;
}
void init() {
  for (int i = 1; i <= n; ++i) fa[i] = i;
}
bool cmp(edge a, edge b) { return a.w < b.w; }
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
void solve() {
  sort(e + 1, e + m + 1, cmp);
  init();
  for (int i = 1; i <= m; ++i) {
    int u = e[i].u, v = e[i].v;
    if (Find(u) ^ Find(v)) {
      fa[Find(u)] = Find(v);
      ok[e[i].i] = 1;
      addEdge(u, v, e[i].w, e[i].i), addEdge(v, u, e[i].w, e[i].i);
    }
  }
}
void dfs(int u, int ba) {
  dep[u] = dep[ba] + 1;
  f[u][0] = ba;
  for (int i = 1; i <= 20; ++i)
    f[u][i] = f[f[u][i - 1]][i - 1],
    mx[u][i] = max(mx[u][i - 1], mx[f[u][i - 1]][i - 1]);
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == ba) continue;
    mx[v][0] = val[i];
    line[v] = ip[i];
    dfs(v, u);
  }
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int r = 0;
  for (int i = 20; i >= 0; --i)
    if (dep[f[u][i]] >= dep[v]) {
      r = max(r, mx[u][i]);
      u = f[u][i];
    }
  if (u == v) return r;
  for (int i = 20; i >= 0; --i) {
    if (f[u][i] ^ f[v][i]) {
      r = max(r, max(mx[u][i], mx[v][i]));
      u = f[u][i], v = f[v][i];
    }
  }
  return max(r, max(mx[u][0], mx[v][0]));
}
int Lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 20; i >= 0; --i)
    if (dep[f[u][i]] >= dep[v]) {
      u = f[u][i];
    }
  if (u == v) return u;
  for (int i = 20; i >= 0; --i) {
    if (f[u][i] ^ f[v][i]) {
      u = f[u][i], v = f[v][i];
    }
  }
  return f[u][0];
}
void jump(int u, int v, int w) {
  int lca = Lca(u, v);
  if (Find(u) ^ u) u = Find(u);
  if (Find(v) ^ v) v = Find(v);
  while (dep[u] > dep[lca]) {
    ans[line[u]] = w;
    fa[u] = Find(f[u][0]);
    u = Find(f[u][0]);
  }
  while (dep[v] > dep[lca]) {
    ans[line[v]] = w;
    fa[v] = Find(f[v][0]);
    v = Find(f[v][0]);
  }
}
int main() {
  memset(ans, -1, sizeof ans);
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w);
    e[i].i = i;
  }
  solve();
  init();
  dfs(1, 0);
  for (int i = 1; i <= m; ++i) {
    if (ok[e[i].i]) continue;
    ans[e[i].i] = LCA(e[i].u, e[i].v);
    E[++p] = e[i];
  }
  for (int i = 1; i <= p; ++i) jump(E[i].u, E[i].v, E[i].w);
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i] == -1 ? inf : ans[i]);
  return 0;
}
