#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 100010;
int ufds[N];
int n, m;
vector<tuple<int, int, int, int> > ve;
vector<tuple<int, int, int> > g[N];
int find(int x) {
  if (x == ufds[x]) return x;
  return ufds[x] = find(ufds[x]);
}
void unio(int x, int y) { ufds[find(x)] = find(y); }
const int LOGN = 18;
int p[N][LOGN], mi[N][LOGN];
int depth[N];
int pid[N];
vector<int> lvl[N];
multiset<ii> upd[N];
int where[N];
void dfs(int u, int last, int d) {
  depth[u] = d;
  lvl[d].push_back(u);
  for (auto& edg : g[u]) {
    int v, w, id;
    tie(v, w, id) = edg;
    if (v == last) continue;
    pid[v] = id;
    p[v][0] = u;
    mi[v][0] = w;
    dfs(v, u, d + 1);
  }
}
const int M = 1000010;
int ans[M];
ii query(int a, int b) {
  int ret = 0;
  if (depth[a] != depth[b]) {
    if (depth[a] > depth[b]) swap(a, b);
    int diff = depth[b] - depth[a];
    for (int i = 0; diff >> i; i++) {
      if ((diff >> i) & 1) {
        ret = max(ret, mi[b][i]);
        b = p[b][i];
      }
    }
  }
  if (a == b) return {ret, a};
  for (int i = LOGN - 1; i >= 0; i--) {
    if (p[a][i] != p[b][i]) {
      ret = max({ret, mi[a][i], mi[b][i]});
      a = p[a][i];
      b = p[b][i];
    }
  }
  ret = max({ret, mi[a][0], mi[b][0]});
  return {ret, p[a][0]};
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    ve.emplace_back(w, u, v, i);
  }
  sort(ve.begin(), ve.end());
  iota(ufds + 1, ufds + n + 1, 1);
  for (int i = 0; i < ve.size(); i++) {
    int u, v, w, id;
    tie(w, u, v, id) = ve[i];
    if (find(u) != find(v)) {
      unio(u, v);
      g[u].emplace_back(v, w, id);
      g[v].emplace_back(u, w, id);
      ans[id] = -1;
    }
  }
  dfs(1, 0, 0);
  for (int i = 1; i < LOGN; i++) {
    for (int u = 1; u <= n; u++) {
      p[u][i] = p[p[u][i - 1]][i - 1];
      mi[u][i] = max(mi[u][i - 1], mi[p[u][i - 1]][i - 1]);
    }
  }
  for (int i = 0; i < m; i++) {
    int u, v, w, id;
    tie(w, u, v, id) = ve[i];
    if (ans[id] == -1) continue;
    if (depth[u] > depth[v]) swap(u, v);
    ii res = query(u, v);
    ans[id] = res.first;
    int l = res.second;
    if (l == u)
      upd[v].emplace(w, depth[u] + 1);
    else {
      upd[u].emplace(w, depth[l] + 1);
      upd[v].emplace(w, depth[l] + 1);
    }
  }
  iota(where + 1, where + n + 1, 1);
  for (int lv = N - 1; lv > 0; lv--) {
    for (int u : lvl[lv]) {
      for (auto& tu : g[u]) {
        int v = get<0>(tu);
        if (depth[v] < depth[u]) continue;
        if (upd[where[u]].size() > upd[where[v]].size()) {
          upd[where[u]].insert(upd[where[v]].begin(), upd[where[v]].end());
          upd[where[v]].clear();
        } else {
          upd[where[v]].insert(upd[where[u]].begin(), upd[where[u]].end());
          upd[where[u]].clear();
          where[u] = where[v];
        }
      }
      int wu = where[u];
      while (!upd[wu].empty() and upd[wu].begin()->second > depth[u])
        upd[wu].erase(upd[wu].begin());
      ans[pid[u]] = upd[wu].empty() ? 1000000000 : upd[wu].begin()->first;
    }
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
