#include <bits/stdc++.h>
using namespace std;
int mstPar[100005];
int root(int a) {
  if (a == mstPar[a]) return a;
  return mstPar[a] = root(mstPar[a]);
}
bool inMst[1000005];
multiset<int> ews[100005];
vector<int> vrem[100005], vadd[100005];
int ans[1000005];
namespace tree {
struct Edge {
  int cost;
  int id;
};
int n;
vector<Edge> edges;
vector<vector<pair<int, int>>> adj;
void makeTree(int _n) {
  n = _n;
  adj = vector<vector<pair<int, int>>>(n + 1);
}
template <typename... T>
int addEdge(int from, int to, const T&... e) {
  int id = edges.size();
  adj[from].emplace_back(to, id);
  adj[to].emplace_back(from, id);
  edges.push_back({e...});
  return id;
}
vector<int> depth, pv, pe, pre, endpre, preseq, siz;
int logn;
vector<vector<int>> anc;
struct Jump {
  int sum;
  void init(int v) {
    Edge& e = edges[pe[v]];
    sum = e.cost;
  }
  void combine(const Jump& x, const Jump& a) { sum = max(x.sum, a.sum); }
};
vector<vector<Jump>> jump;
void dfs(int x, int p = -1) {
  siz[x] = 1;
  pre[x] = preseq.size();
  preseq.push_back(x);
  for (auto& e : adj[x]) {
    int y = e.first, eid = e.second;
    if (y == p) continue;
    depth[y] = depth[x] + 1;
    pv[y] = x;
    pe[y] = eid;
    dfs(y, x);
    siz[x] += siz[y];
  }
  endpre[x] = (int)preseq.size() - 1;
}
void init(int root = 1) {
  siz = vector<int>(n + 1);
  depth = vector<int>(n + 1);
  pv = vector<int>(n + 1, -1);
  pe = vector<int>(n + 1, -1);
  pre = vector<int>(n + 1, -1);
  endpre = vector<int>(n + 1, -1);
  preseq.clear();
  dfs(root);
  logn = 31 - __builtin_clz(n);
  anc = vector<vector<int>>(n + 1, vector<int>(logn + 1));
  for (int i = 1; i <= n; ++i) anc[i][0] = pv[i];
  for (int p = 1; p <= logn; ++p)
    for (int i = 1; i <= n; ++i)
      anc[i][p] = anc[i][p - 1] == -1 ? -1 : anc[anc[i][p - 1]][p - 1];
  jump = vector<vector<Jump>>(n + 1, vector<Jump>(logn + 1));
  for (int i = 1; i <= n; ++i)
    if (anc[i][0] != -1) jump[i][0].init(i);
  for (int p = 1; p <= logn; ++p)
    for (int i = 1; i <= n; ++i)
      if (anc[i][p] != -1)
        jump[i][p].combine(jump[i][p - 1], jump[anc[i][p - 1]][p - 1]);
}
bool isAnc(int a, int b) { return pre[a] <= pre[b] && endpre[a] >= endpre[b]; }
int getChildTowards(int a, int sub) {
  int dh = depth[sub] - depth[a] - 1;
  for (int p = logn; p >= 0; --p)
    if (dh & (1 << p)) sub = anc[sub][p];
  return sub;
}
int getLca(int a, int b) {
  if (isAnc(a, b)) return a;
  if (isAnc(b, a)) return b;
  for (int p = logn; p >= 0; --p)
    if (anc[a][p] != -1 && !isAnc(anc[a][p], b)) a = anc[a][p];
  a = anc[a][0];
  return a;
}
void jumpUp(int a, int ancestor, function<void(Jump&)> f) {
  assert(isAnc(ancestor, a));
  int up = depth[a] - depth[ancestor];
  for (int p = logn; p >= 0; --p)
    if (up & (1 << p)) {
      f(jump[a][p]);
      a = anc[a][p];
    }
}
vector<int> chainRoot, chainBottom;
void dfsSiz(int x, int p = -1) {
  for (auto it = adj[x].begin(); it != adj[x].end(); ++it)
    if (it->first == p) {
      adj[x].erase(it);
      break;
    }
  siz[x] = 1;
  for (auto& e : adj[x]) {
    int y = e.first;
    dfsSiz(y, x);
    siz[x] += siz[y];
    if (siz[y] > siz[adj[x][0].first]) swap(e, adj[x][0]);
  }
}
void dfsHld(int x, int hldroot) {
  chainRoot[x] = hldroot;
  chainBottom[hldroot] = x;
  for (auto& e : adj[x]) {
    int y = e.first;
    dfsHld(y, y == adj[x][0].first ? hldroot : y);
  }
}
struct Chain {
  vector<int> vs;
  void init(int bot, int top) {
    vs.clear();
    for (int x = bot; x != pv[top]; x = pv[x]) vs.push_back(x);
  }
};
vector<Chain> chains;
void moveUp(int x, int y, function<void(Chain&, int, int)> f) {
  for (;;) {
    int z = chainRoot[x];
    bool isLastChain = z == chainRoot[y];
    f(chains[chainRoot[x]], x, isLastChain ? y : z);
    if (isLastChain) break;
    x = pv[z];
  }
}
void initHld(int root = 1) {
  siz = vector<int>(n + 1);
  dfsSiz(root);
  init(root);
  chainRoot = vector<int>(n + 1);
  chainBottom = vector<int>(n + 1);
  dfsHld(root, root);
  chains = vector<Chain>(n + 1);
  for (int i = 1; i <= n; ++i) {
    if (chainRoot[i] != i) continue;
    chains[i].init(chainBottom[i], i);
  }
}
};  // namespace tree
using namespace tree;
void solve(int x, int p = -1) {
  for (auto& e : adj[x]) {
    int y = e.first;
    if (y == p) continue;
    solve(y, x);
    if (ews[y].size() > ews[x].size()) {
      swap(ews[y], ews[x]);
    }
    for (int z : ews[y]) {
      ews[x].insert(z);
    }
    ews[y].clear();
  }
  for (int z : vadd[x]) {
    ews[x].insert(z);
  }
  for (int z : vrem[x]) {
    ews[x].erase(ews[x].find(z));
  }
  if (p == -1) {
    assert(ews[x].empty());
  } else {
    0;
    auto& e = edges[pe[x]];
    int eid = e.id;
    0;
    ans[eid] = 1000000000;
    if (!ews[x].empty()) {
      assert(*ews[x].begin() >= e.cost);
      ans[eid] = *ews[x].begin();
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  makeTree(n);
  vector<pair<int, int>> edges(m);
  vector<pair<int, pair<int, int>>> origEdges(m);
  for (int i = 0; i < m; ++i) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    origEdges[i] = {w, {a, b}};
    edges[i] = {w, i};
  }
  sort(edges.begin(), edges.end());
  iota(mstPar, mstPar + n + 1, 0);
  int mstCnt = 0;
  for (int i = 0; i < m; ++i) {
    int a, b, w, eid;
    tie(w, eid) = edges[i];
    tie(a, b) = origEdges[eid].second;
    int ra = root(a);
    int rb = root(b);
    if (ra == rb) continue;
    mstPar[ra] = rb;
    0;
    addEdge(a, b, w, eid);
    inMst[eid] = true;
    ++mstCnt;
  }
  assert(mstCnt == n - 1);
  init();
  for (int i = 0; i < m; ++i) {
    int a, b, w = origEdges[i].first;
    tie(a, b) = origEdges[i].second;
    if (!inMst[i]) {
      int lca = getLca(a, b);
      vadd[a].push_back(w);
      vadd[b].push_back(w);
      vrem[lca].push_back(w);
      vrem[lca].push_back(w);
    }
  }
  solve(1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    tie(a, b) = origEdges[i].second;
    if (!inMst[i]) {
      int lca = getLca(a, b);
      int ret = 0;
      auto f = [&](Jump& jump) { ret = max(ret, jump.sum); };
      jumpUp(a, lca, f);
      jumpUp(b, lca, f);
      ans[i] = ret;
    }
  }
  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}
