#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int K = 20;
vector<int> g[N];
int a[N], b[N], c[N], p[N], ord[N], used[N], par[K][N], maxi[K][N], depth[N],
    ans[N], nxt[N], pari[N];
int find(int v) { return (p[v] < 0) ? v : (p[v] = find(p[v])); }
bool combine(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) {
    return false;
  }
  if (p[u] > p[v]) swap(u, v);
  p[u] += p[v];
  p[v] = u;
  return true;
}
void dfs(int v, int p) {
  depth[v] = depth[p] + 1;
  par[0][v] = p;
  for (int i : g[v]) {
    int u = a[i] ^ b[i] ^ v;
    if (u == p) continue;
    maxi[0][u] = c[i];
    pari[u] = i;
    dfs(u, v);
  }
}
inline int get(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int dif = depth[u] - depth[v];
  int ret = 0;
  for (int i = K - 1; i >= 0; i--) {
    if ((dif >> i) & 1) {
      ret = max(ret, maxi[i][u]);
      u = par[i][u];
    }
  }
  if (u == v) return ret;
  for (int i = K - 1; i >= 0; i--) {
    if (par[i][u] != par[i][v]) {
      ret = max(ret, maxi[i][u]);
      ret = max(ret, maxi[i][v]);
      u = par[i][u];
      v = par[i][v];
    }
  }
  ret = max(ret, maxi[0][u]);
  ret = max(ret, maxi[0][v]);
  return ret;
}
inline int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int dif = depth[u] - depth[v];
  for (int i = K - 1; i >= 0; i--) {
    if ((dif >> i) & 1) {
      u = par[i][u];
    }
  }
  if (u == v) return u;
  for (int i = K - 1; i >= 0; i--) {
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  }
  return par[0][u];
}
inline void update(int v, int u, int x) {
  int w = v;
  while (true) {
    v = nxt[v];
    if (depth[v] <= depth[u]) break;
    int i = pari[v];
    if (ans[i] == -1) {
      ans[i] = x;
    }
    v ^= a[i] ^ b[i];
  }
  while (true) {
    w = nxt[w];
    if (depth[w] <= depth[u]) break;
    int i = pari[w];
    nxt[w] = v;
    w ^= a[i] ^ b[i];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  memset(p, -1, sizeof(p));
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    ord[i] = i;
    nxt[i] = i;
  }
  sort(ord + 1, ord + m + 1, [&](int i, int j) { return c[i] < c[j]; });
  for (int i = 1; i <= m; i++) {
    int j = ord[i];
    if (combine(a[j], b[j])) {
      g[a[j]].push_back(j);
      g[b[j]].push_back(j);
      used[j] = 1;
    }
  }
  depth[0] = 0;
  dfs(1, 0);
  for (int k = 1; k < K; k++) {
    par[k - 1][0] = 0;
    maxi[k - 1][0] = 0;
    for (int i = 1; i <= n; i++) {
      par[k][i] = par[k - 1][par[k - 1][i]];
      maxi[k][i] = max(maxi[k - 1][i], maxi[k - 1][par[k - 1][i]]);
    }
  }
  memset(ans, -1, sizeof(ans));
  for (int i = 1; i <= m; i++) {
    int j = ord[i];
    if (used[j]) continue;
    ans[j] = get(a[j], b[j]);
    int w = lca(a[j], b[j]);
    update(a[j], w, c[j]);
    update(b[j], w, c[j]);
  }
  for (int i = 1; i <= m; i++) {
    if (ans[i] == -1)
      cout << 1000000000 << '\n';
    else
      cout << ans[i] << '\n';
  }
  return 0;
}
