#include <bits/stdc++.h>
using namespace std;
struct DSU {
  vector<int> rank;
  vector<int> parent;
  DSU(int n) {
    rank.resize(n, 1);
    parent.resize(n);
    for (int i = 0; i < n; ++i) parent[i] = i;
  }
  int find(const int u) {
    return parent[u] == u ? u : (parent[u] = find(parent[u]));
  }
  bool merge(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return false;
    if (rank[u] < rank[v]) swap(u, v);
    rank[u] += rank[v];
    parent[v] = u;
    return true;
  }
  int size(int u) { return rank[find(u)]; }
};
const int MxN = (int)1e5 + 9;
vector<pair<int, int>> adj[MxN + 9];
int depth[MxN + 9];
vector<pair<int, int>> parent[MxN + 9];
vector<int> inserts[MxN + 9];
vector<int> deletes[MxN + 9];
multiset<int> merge(multiset<int> &ms1, multiset<int> &ms2) {
  if (ms1.size() > ms2.size()) swap(ms1, ms2);
  ms2.insert(ms1.begin(), ms1.end());
  return move(ms2);
}
multiset<int> dfs2(const int u, map<pair<int, int>, int> &res2) {
  multiset<int> ms;
  for (const auto e : adj[u]) {
    const int v = e.first;
    if (!parent[u].empty() && v == parent[u][0].first) continue;
    multiset<int> m = dfs2(v, res2);
    res2[{u, v}] = m.empty() ? (int)1e9 : *m.begin();
    ms = merge(ms, m);
  }
  for (int x : deletes[u]) {
    auto it = ms.find(x);
    assert(it != ms.end());
    ms.erase(it);
  }
  ms.insert(inserts[u].begin(), inserts[u].end());
  return move(ms);
}
void dfs1(const int u, const int p) {
  for (const auto e : adj[u]) {
    const int v = e.first;
    const int w = e.second;
    if (v != p) {
      depth[v] = depth[u] + 1;
      parent[v] = {{u, w}};
      for (int i = 0; i < (int)parent[parent[v][i].first].size(); ++i)
        parent[v].push_back(
            {parent[parent[v][i].first][i].first,
             max(parent[v][i].second, parent[parent[v][i].first][i].second)});
      dfs1(v, u);
    }
  }
}
pair<int, int> lca(int u, int v) {
  int diff = depth[u] - depth[v];
  if (diff < 0) {
    swap(u, v);
    diff = -diff;
  }
  int res = 0;
  for (int i = 0; diff; ++i)
    if (diff & (1 << i)) {
      diff ^= 1 << i;
      res = max(res, parent[u][i].second);
      u = parent[u][i].first;
    }
  if (u != v) {
    for (int i = (int)parent[u].size() - 1; i >= 0; --i)
      if (parent[u][i].first != parent[v][i].first) {
        res = max(res, parent[u][i].second);
        res = max(res, parent[v][i].second);
        u = parent[u][i].first;
        v = parent[v][i].first;
        i = min(i, (int)parent[u].size());
      }
    assert(u != v);
    res = max(res, parent[u][0].second);
    res = max(res, parent[v][0].second);
    u = parent[u][0].first;
    v = parent[v][0].first;
    assert(u == v);
  }
  return {u, res};
}
struct Edge {
  int u, v, w;
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<Edge> edges(m);
  for (auto &&e : edges) cin >> e.u >> e.v >> e.w;
  vector<bool> taken(m, false);
  {
    vector<int> ids(m);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&edges](const int i, const int j) {
      return edges[i].w < edges[j].w;
    });
    DSU dsu(n + 1);
    for (int i = 0; i < m; ++i) {
      const int u = edges[ids[i]].u;
      const int v = edges[ids[i]].v;
      const int w = edges[ids[i]].w;
      if ((taken[ids[i]] = dsu.merge(u, v))) {
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
      }
    }
  }
  dfs1(1, -1);
  map<pair<int, int>, int> res2;
  {
    for (int i = 0; i < m; ++i)
      if (!taken[i]) {
        const int u = edges[i].u;
        const int v = edges[i].v;
        const int w = edges[i].w;
        const int x = lca(u, v).first;
        for (int y : {u, v})
          if (y != x) {
            inserts[y].push_back(w);
            deletes[x].push_back(w);
          }
      }
    multiset<int> ms = dfs2(1, res2);
    assert(ms.empty());
  }
  for (int i = 0; i < m; ++i) {
    if (!taken[i])
      cout << lca(edges[i].u, edges[i].v).second << '\n';
    else {
      auto it1 = res2.find({edges[i].u, edges[i].v});
      auto it2 = res2.find({edges[i].v, edges[i].u});
      assert((it1 == res2.end()) != (it2 == res2.end()));
      auto it = it1 == res2.end() ? it2 : it1;
      cout << it->second << '\n';
    }
  }
  return 0;
}
