#include <bits/stdc++.h>
const int INF = 2000000005;
const long long BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const long double PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector<pair<int, int> > dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid(int x, int y, int n, int m) {
  return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
const int N = 1000000 + 50, logN = 18;
int p[N], dp[N][logN], h[N], mx[N][logN], a[N], b[N], c[N], order[N], ans[N], n,
    m;
bool taken[N];
vector<pair<int, int> > g[N];
bool comp(int x, int y) { return c[x] < c[y]; }
int find_set(int v) {
  if (p[v] == v) return v;
  p[v] = find_set(p[v]);
  return p[v];
}
void dfs(int v, int p) {
  dp[v][0] = p;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first, w = g[v][i].second;
    if (to == p) continue;
    mx[to][0] = w;
    h[to] = h[v] + 1;
    dfs(to, v);
  }
}
inline void build_dp() {
  for (int j = 1; j < logN; j++) {
    for (int i = 0; i < n; i++) {
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
      mx[i][j] = max(mx[i][j - 1], mx[dp[i][j - 1]][j - 1]);
    }
  }
}
inline int upper(int v, int d) {
  while (d > 0) {
    v = dp[v][__builtin_ctz(d)];
    d &= d - 1;
  }
  return v;
}
inline int getMax(int v, int d) {
  int res = 0;
  while (d > 0) {
    res = max(res, mx[v][__builtin_ctz(d)]);
    v = dp[v][__builtin_ctz(d)];
    d &= d - 1;
  }
  return res;
}
inline int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  u = upper(u, h[u] - h[v]);
  if (u == v) return u;
  for (int j = logN - 1; j >= 0; j--) {
    if (dp[u][j] != dp[v][j]) u = dp[u][j], v = dp[v][j];
  }
  return dp[v][0];
}
map<pair<int, int>, int> ind;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  fill(ans, ans + N, 1000000000);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    p[i] = i;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    order[i] = i;
  }
  sort(order, order + m, comp);
  for (int i = 0; i < m; i++) {
    int u = a[order[i]], v = b[order[i]];
    if (find_set(u) != find_set(v)) {
      taken[order[i]] = true;
      g[u].push_back(make_pair(v, c[order[i]]));
      g[v].push_back(make_pair(u, c[order[i]]));
      p[find_set(u)] = find_set(v);
      ind[make_pair(u, v)] = order[i];
      ind[make_pair(v, u)] = order[i];
    }
  }
  dfs(0, 0);
  build_dp();
  for (int i = 0; i < m; i++) {
    if (!taken[i]) {
      int u = a[i], v = b[i], lc = lca(u, v);
      int mxval = max(getMax(u, h[u] - h[lc]), getMax(v, h[v] - h[lc]));
      ans[i] = mxval;
    }
  }
  for (int i = 0; i < n; i++) {
    p[i] = i;
  }
  for (int i = 0; i < m; i++) {
    if (taken[order[i]]) continue;
    int u = a[order[i]], v = b[order[i]], lc = lca(u, v);
    u = find_set(u);
    while (h[u] > h[lc]) {
      ans[ind[make_pair(u, dp[u][0])]] = c[order[i]];
      p[u] = find_set(dp[u][0]);
      u = find_set(dp[u][0]);
    }
    v = find_set(v);
    while (h[v] > h[lc]) {
      ans[ind[make_pair(v, dp[v][0])]] = c[order[i]];
      p[v] = find_set(dp[v][0]);
      v = find_set(dp[v][0]);
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
