#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int n, m;
struct Ed {
  int x;
  int y;
  int w;
  int id;
  bool f;
  bool operator<(const Ed &t) const { return w < t.w; }
} ed[1000005 << 1];
int fi[200005];
int findd(int x) {
  if (x == fi[x])
    return x;
  else
    return fi[x] = findd(fi[x]);
}
struct Edge {
  int to;
  int nex;
  int w;
} e[1000005 << 1];
int head[200005], tot;
void add(int u, int v, int w) {
  e[tot].to = v;
  e[tot].w = w;
  e[tot].nex = head[u];
  head[u] = tot++;
}
void kruskal() {
  for (int i = 1; i <= n; i++) fi[i] = i;
  int num = 0;
  sort(ed + 1, ed + m + 1);
  for (int i = 1; i <= m; i++) {
    int x = ed[i].x;
    int y = ed[i].y;
    int fx = findd(x);
    int fy = findd(y);
    if (fx != fy) {
      fi[fx] = fy;
      ed[i].f = 1;
      num++;
      add(x, y, ed[i].w);
      add(y, x, ed[i].w);
    }
    if (num == n - 1) break;
  }
}
int mx[200005][22], mn[200005][22], f[200005][22];
int d[200005];
void dfs(int x, int fa) {
  f[x][0] = fa;
  for (int i = head[x]; i != -1; i = e[i].nex) {
    int y = e[i].to;
    if (y == fa) continue;
    d[y] = d[x] + 1;
    mx[y][0] = e[i].w;
    dfs(y, x);
  }
}
void update(int x, int y, int w) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = 20; i >= 0; i--) {
    if (d[f[x][i]] >= d[y]) {
      mn[x][i] = min(mn[x][i], w);
      x = f[x][i];
    }
  }
  if (x == y) return;
  for (int i = 20; i >= 0; i--) {
    if (f[x][i] != f[y][i]) {
      mn[x][i] = min(mn[x][i], w);
      mn[y][i] = min(mn[y][i], w);
      x = f[x][i];
      y = f[y][i];
    }
  }
  mn[x][0] = min(mn[x][0], w);
  mn[y][0] = min(mn[y][0], w);
}
int lca(int x, int y) {
  int ans = 0;
  if (d[x] < d[y]) swap(x, y);
  for (int i = 20; i >= 0; i--) {
    if (d[f[x][i]] >= d[y]) {
      ans = max(ans, mx[x][i]);
      x = f[x][i];
    }
  }
  if (x == y) return ans;
  for (int i = 20; i >= 0; i--) {
    if (f[x][i] != f[y][i]) {
      ans = max(ans, mx[x][i]);
      ans = max(ans, mx[y][i]);
      x = f[x][i];
      y = f[y][i];
    }
  }
  ans = max(ans, mx[x][0]);
  ans = max(ans, mx[y][0]);
  return ans;
}
int ans[1000005];
int main() {
  memset(head, -1, sizeof head);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &ed[i].x, &ed[i].y, &ed[i].w);
    ed[i].id = i;
  }
  kruskal();
  for (int i = 0; i <= 20; i++) {
    for (int j = 1; j <= n; j++) mn[j][i] = inf;
  }
  dfs(1, 1);
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) {
      f[j][i] = f[f[j][i - 1]][i - 1];
      mx[j][i] = max(mx[j][i - 1], mx[f[j][i - 1]][i - 1]);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (ed[i].f) continue;
    update(ed[i].x, ed[i].y, ed[i].w);
    int res = lca(ed[i].x, ed[i].y);
    ans[ed[i].id] = res;
  }
  for (int i = 19; i >= 0; i--) {
    for (int j = 1; j <= n; j++) {
      mn[j][i] = min(mn[j][i], mn[j][i + 1]);
      mn[f[j][i]][i] = min(mn[f[j][i]][i], mn[j][i + 1]);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (!ed[i].f) continue;
    if (d[ed[i].x] > d[ed[i].y])
      ans[ed[i].id] = mn[ed[i].x][0];
    else
      ans[ed[i].id] = mn[ed[i].y][0];
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
}
