#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
const int N = 1000005;
int read() {
  int x = 0, f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9') {
    if (c == '-') f = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int n, m, tot, f[M], fa[M], dep[M], id[M];
int p[M][20], mx[M][20], ans[N], used[N];
struct node {
  int u, v, c, id;
  bool operator<(const node &b) const { return c < b.c; }
} a[N];
struct edge {
  int v, c, id, next;
} e[2 * M];
void dfs(int u, int pr) {
  p[u][0] = pr;
  dep[u] = dep[pr] + 1;
  for (int i = 1; i < 20; i++) {
    int tmp = p[u][i - 1];
    p[u][i] = p[tmp][i - 1];
    mx[u][i] = max(mx[u][i - 1], mx[tmp][i - 1]);
  }
  for (int i = f[u]; i; i = e[i].next) {
    int v = e[i].v;
    if (v == pr) continue;
    mx[v][0] = e[i].c;
    id[v] = e[i].id;
    dfs(v, u);
  }
}
pair<int, int> lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int x = 0;
  for (int i = 19; i >= 0; i--)
    if (dep[p[u][i]] >= dep[v]) {
      x = max(x, mx[u][i]);
      u = p[u][i];
    }
  if (u == v) return make_pair(u, x);
  for (int i = 19; i >= 0; i--)
    if (p[u][i] ^ p[v][i]) {
      x = max(x, max(mx[u][i], mx[v][i]));
      u = p[u][i];
      v = p[v][i];
    }
  x = max(x, max(mx[u][0], mx[v][0]));
  return make_pair(p[u][0], x);
}
int find(int x) {
  if (x != fa[x]) fa[x] = find(fa[x]);
  return fa[x];
}
signed main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    ans[i] = -1;
    a[i].u = read();
    a[i].v = read();
    a[i].c = read();
    a[i].id = i;
  }
  sort(a + 1, a + 1 + m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int u = a[i].u, v = a[i].v, id = a[i].id, c = a[i].c;
    int x = find(u), y = find(v);
    if (x == y) continue;
    fa[x] = y;
    used[i] = 1;
    e[++tot] = edge{v, c, id, f[u]}, f[u] = tot;
    e[++tot] = edge{u, c, id, f[v]}, f[v] = tot;
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  dfs(1, 0);
  for (int i = 1; i <= m; i++) {
    if (used[i]) continue;
    int u = a[i].u, v = a[i].v;
    pair<int, int> tmp = lca(u, v);
    int t = tmp.first;
    while (dep[u] > dep[t]) {
      if (ans[id[u]] == -1) {
        ans[id[u]] = a[i].c;
        fa[u] = find(p[u][0]);
      }
      u = find(p[u][0]);
    }
    while (dep[v] > dep[t]) {
      if (ans[id[v]] == -1) {
        ans[id[v]] = a[i].c;
        fa[v] = find(p[v][0]);
      }
      v = find(p[v][0]);
    }
    ans[a[i].id] = tmp.second;
  }
  for (int i = 1; i <= m; i++) {
    if (ans[i] == -1)
      printf("1000000000\n");
    else
      printf("%d\n", ans[i]);
  }
}
