#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int maxk = 18;
vector<pair<int, int> > wek[maxn];
int pre[maxn], post[maxn];
int f[maxn][maxk];
int maxi[maxn][maxk];
int dp[maxn][maxk];
int F[maxn];
int deep[maxn];
map<pair<int, int>, int> mapa;
int t;
int odp[maxn * 10];
set<pair<int, int> >* wsk[maxn];
bool czy(int a, int b) { return pre[a] <= pre[b] && post[b] <= post[a]; }
int fin(int x) {
  if (F[x] != x) F[x] = fin(F[x]);
  return F[x];
}
void uni(int a, int b) { F[fin(a)] = fin(b); }
void dfs(int x) {
  pre[x] = t++;
  for (auto s : wek[x])
    if (s.first != f[x][0]) {
      f[s.first][0] = x;
      maxi[s.first][0] = s.second;
      deep[s.first] = deep[x] + 1;
      dfs(s.first);
    }
  post[x] = t++;
}
int lca(int a, int b) {
  int k = maxk - 1;
  while (k >= 0) {
    if (!czy(f[a][k], b)) a = f[a][k];
    k--;
  }
  if (!czy(a, b)) a = f[a][0];
  return a;
}
int daj(int x) {
  int k = 1;
  while ((1 << k) < x) k++;
  k--;
  assert((1 << k) <= x && (1 << (k + 1)) >= x);
  return k;
}
int skok(int x, int ile) {
  int k = maxk - 1;
  while (k >= 0) {
    if ((1 << k) & ile) x = f[x][k];
    k--;
  }
  return x;
}
int ma(int a, int b) {
  int res = 0;
  int k = maxk - 1;
  while (k >= 0) {
    if (!czy(f[a][k], b)) {
      res = max(maxi[a][k], res);
      a = f[a][k];
    }
    k--;
  }
  if (!czy(a, b)) {
    res = max(res, maxi[a][0]);
    a = f[a][0];
  }
  k = maxk - 1;
  while (k >= 0) {
    if (!czy(f[b][k], a)) {
      res = max(maxi[b][k], res);
      b = f[b][k];
    }
    k--;
  }
  if (!czy(b, a)) {
    res = max(res, maxi[b][0]);
    b = f[b][0];
  }
  assert(a == b);
  return res;
}
int licz(int a, int b) {
  int res = 1000000000;
  int k = maxk - 1;
  while (k >= 0) {
    if (!czy(f[a][k], b)) {
      res = min(dp[a][k], res);
      a = f[a][k];
    }
    k--;
  }
  if (!czy(a, b)) {
    res = min(res, dp[a][0]);
    a = f[a][0];
  }
  k = maxk - 1;
  while (k >= 0) {
    if (!czy(f[b][k], a)) {
      res = min(dp[b][k], res);
      b = f[b][k];
    }
    k--;
  }
  if (!czy(b, a)) {
    res = min(res, dp[b][0]);
    b = f[b][0];
  }
  assert(a == b);
  return res;
}
void dodaj(int dol, int gora, int c) {
  if (dol == gora) return;
  int k = daj(deep[dol] - deep[gora]);
  dp[dol][k] = min(dp[dol][k], c);
  dol = skok(dol, deep[dol] - deep[gora] - (1 << k));
  dp[dol][k] = min(dp[dol][k], c);
}
int main() {
  vector<vector<int> > xd, xdxd, xdxdxd;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    odp[i] = -1;
    int a, b, c;
    cin >> a >> b >> c;
    mapa[{a, b}] = i;
    mapa[{b, a}] = i;
    xd.push_back({c, a, b});
  }
  sort((xd).begin(), (xd).end());
  for (int i = 1; i <= n; i++) F[i] = i;
  for (auto s : xd) {
    if (fin(s[1]) != fin(s[2])) {
      wek[s[1]].push_back({s[2], s[0]});
      wek[s[2]].push_back({s[1], s[0]});
      uni(s[1], s[2]);
      xdxdxd.push_back(s);
    } else
      xdxd.push_back(s);
  }
  dfs(1);
  f[1][0] = 1;
  for (int k = 1; k < maxk; k++)
    for (int i = 1; i <= n; i++) {
      f[i][k] = f[f[i][k - 1]][k - 1];
      maxi[i][k] = max(maxi[i][k - 1], maxi[f[i][k - 1]][k - 1]);
    }
  for (int k = 0; k < maxk; k++)
    for (int i = 1; i <= n; i++) dp[i][k] = 1000000000;
  for (auto s : xdxd) {
    odp[mapa[{s[1], s[2]}]] = ma(s[1], s[2]);
    int lc = lca(s[1], s[2]);
    dodaj(s[1], lc, s[0]);
    dodaj(s[2], lc, s[0]);
  }
  for (int k = maxk - 1; k > 0; k--)
    for (int i = 1; i <= n; i++) {
      dp[i][k - 1] = min(dp[i][k - 1], dp[i][k]);
      dp[f[i][k - 1]][k - 1] = min(dp[f[i][k - 1]][k - 1], dp[i][k]);
    }
  for (int k = 1; k < maxk; k++)
    for (int i = 1; i <= n; i++)
      dp[i][k] = min(dp[i][k - 1], dp[f[i][k - 1]][k - 1]);
  for (auto s : xdxdxd) odp[mapa[{s[1], s[2]}]] = licz(s[1], s[2]);
  for (int i = 1; i <= m; i++) {
    assert(odp[i] >= 0);
    cout << odp[i] << "\n";
  }
  return 0;
}
