#include <bits/stdc++.h>
using namespace std;
const int N = 200005, M = 1000005;
int ne[N], top[N], f[N], fi[N], zz[N], sl[N], tot, sd[N], fa[N][20], val[N][20],
    n, m, Ans[M], p[N], rk[N], son[N], size[N];
vector<int> I[N], E[N];
multiset<int> S;
struct Tree {
  int l, r, num;
} T[N * 4];
struct Ask {
  int x, y, z, from, flag;
} A[M];
inline int findfa(int x) {
  if (x == f[x]) return x;
  return f[x] = findfa(f[x]);
}
inline int cmp(Ask x, Ask y) { return x.z < y.z; }
inline void jb(int x, int y, int z) {
  ne[++tot] = fi[x];
  fi[x] = tot;
  zz[tot] = y;
  sl[tot] = z;
}
inline void dfs(int x, int y, int z) {
  sd[x] = z;
  fa[x][0] = y;
  size[x] = 1;
  for (int i = fi[x]; i; i = ne[i])
    if (zz[i] != y) {
      dfs(zz[i], x, z + 1);
      size[x] += size[zz[i]];
      if (size[son[x]] < size[zz[i]]) son[x] = zz[i];
      val[zz[i]][0] = sl[i];
    }
}
inline void dfs2(int x, int y) {
  top[x] = y;
  rk[x] = ++tot;
  if (son[x]) dfs2(son[x], y);
  for (int i = fi[x]; i; i = ne[i])
    if (zz[i] != fa[x][0] && zz[i] != son[x]) dfs2(zz[i], zz[i]);
}
inline void build(int x, int l, int r) {
  T[x].l = l;
  T[x].r = r;
  T[x].num = 1e9;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
}
inline void insert(int x, int l, int r, int z) {
  if (T[x].l > r || l > T[x].r) return;
  if (T[x].l >= l && T[x].r <= r) {
    T[x].num = min(T[x].num, z);
    return;
  }
  insert(x * 2, l, r, z);
  insert(x * 2 + 1, l, r, z);
}
inline int find(int x, int y) {
  if (T[x].l == T[x].r) return T[x].num;
  int mid = (T[x].l + T[x].r) / 2;
  if (y <= mid) return min(T[x].num, find(x * 2, y));
  return min(T[x].num, find(x * 2 + 1, y));
}
inline void Insert(int x, int y, int z) {
  int fx = top[x], fy = top[y];
  while (fx != fy) {
    if (sd[fx] < sd[fy]) {
      swap(fx, fy);
      swap(x, y);
    }
    insert(1, rk[fx], rk[x], z);
    x = fa[fx][0];
    fx = top[x];
  }
  if (rk[x] < rk[y]) swap(x, y);
  insert(1, rk[y] + 1, rk[x], z);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &A[i].x, &A[i].y, &A[i].z), A[i].from = i;
  sort(A + 1, A + m + 1, cmp);
  for (int i = 1; i <= n; i++) f[i] = i;
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    int x = findfa(A[i].x), y = findfa(A[i].y);
    if (x != y) {
      f[x] = y;
      jb(A[i].x, A[i].y, A[i].z);
      jb(A[i].y, A[i].x, A[i].z);
      cnt++;
    } else
      A[i].flag = 1;
  }
  tot = 0;
  dfs(1, 0, 1);
  dfs2(1, 1);
  for (int i = 1; i <= 19; i++)
    for (int j = 1; j <= n; j++)
      fa[j][i] = fa[fa[j][i - 1]][i - 1],
      val[j][i] = max(val[j][i - 1], val[fa[j][i - 1]][i - 1]);
  build(1, 1, n);
  for (int i = 1; i <= m; i++)
    if (A[i].flag) {
      int x = A[i].x, y = A[i].y;
      if (sd[x] < sd[y]) swap(x, y);
      int num = 0;
      for (int j = 19; j >= 0; j--)
        if (sd[fa[x][j]] >= sd[y]) num = max(num, val[x][j]), x = fa[x][j];
      for (int j = 19; j >= 0; j--)
        if (fa[x][j] != fa[y][j])
          num = max(num, max(val[x][j], val[y][j])), x = fa[x][j], y = fa[y][j];
      if (x != y)
        num = max(num, val[x][0]), x = fa[x][0], num = max(num, val[y][0]),
        y = fa[x][0];
      Ans[A[i].from] = num;
      Insert(A[i].x, A[i].y, A[i].z);
    }
  S.insert(1e9);
  for (int i = 1; i <= m; i++)
    if (!A[i].flag) {
      if (fa[A[i].x][0] == A[i].y)
        Ans[A[i].from] = find(1, rk[A[i].x]);
      else
        Ans[A[i].from] = find(1, rk[A[i].y]);
    }
  for (int i = 1; i <= m; i++) printf("%d\n", Ans[i]);
}
