#include <bits/stdc++.h>
using namespace std;
const int maxn = 112345;
const int maxm = 1123456;
struct Edge {
  int id, w, u, v;
  bool operator<(const Edge &rhs) const { return w < rhs.w; }
};
vector<pair<int, int> > G[maxn];
int anc[maxn][18], mx[maxn][18], mn[maxn][18], par[maxn], ans[maxm], dep[maxn];
int n, m;
void dfs(int u, int p, int w) {
  anc[u][0] = p;
  mx[u][0] = w;
  mn[u][0] = 1e9;
  dep[u] = dep[p] + 1;
  for (int(i) = (1); (i) <= (17); (i)++) {
    anc[u][i] = anc[anc[u][i - 1]][i - 1];
    mx[u][i] = max(mx[anc[u][i - 1]][i - 1], mx[u][i - 1]);
    mn[u][i] = 1e9;
  }
  for (auto _ : G[u])
    if (_.first != p) dfs(_.first, u, _.second);
}
int Find(int x) { return par[x] == x ? x : par[x] = Find(par[x]); }
int main() {
  scanf("%d%d", &n, &m);
  vector<Edge> edges(m);
  for (int(i) = (0); (i) <= ((m)-1); (i)++) {
    auto &x = edges[i];
    scanf("%d%d%d", &x.u, &x.v, &x.w);
    x.id = i;
  }
  sort((edges).begin(), (edges).end());
  iota(par + 1, par + n + 1, 1);
  set<int> vis;
  for (auto x : edges) {
    int u = Find(x.u), v = Find(x.v), w = x.w, id = x.id;
    if (u == v) continue;
    par[u] = v;
    G[x.u].emplace_back(x.v, w);
    G[x.v].emplace_back(x.u, w);
    vis.emplace(id);
  }
  dfs(1, 0, 0);
  memset(ans, -1, sizeof(ans));
  for (auto x : edges)
    if (!vis.count(x.id)) {
      int u = x.u, v = x.v;
      if (dep[u] > dep[v]) swap(u, v);
      int now = 0;
      for (int(i) = (17); (i) >= (0); (i)--)
        if (dep[anc[v][i]] >= dep[u]) {
          now = max(now, mx[v][i]);
          mn[v][i] = min(mn[v][i], x.w);
          v = anc[v][i];
        }
      if (v == u) {
        ans[x.id] = now;
        continue;
      }
      for (int(i) = (17); (i) >= (0); (i)--)
        if (anc[u][i] != anc[v][i]) {
          now = max(now, mx[u][i]);
          now = max(now, mx[v][i]);
          mn[u][i] = min(mn[u][i], x.w);
          mn[v][i] = min(mn[v][i], x.w);
          u = anc[u][i], v = anc[v][i];
        }
      now = max(now, max(mx[u][0], mx[v][0]));
      mn[u][0] = min(mn[u][0], x.w);
      mn[v][0] = min(mn[v][0], x.w);
      ans[x.id] = now;
    }
  for (int(j) = (17); (j) >= (1); (j)--)
    for (int(i) = (1); (i) <= (n); (i)++) {
      mn[i][j - 1] = min(mn[i][j - 1], mn[i][j]);
      mn[anc[i][j - 1]][j - 1] = min(mn[anc[i][j - 1]][j - 1], mn[i][j]);
    }
  sort((edges).begin(), (edges).end(),
       [&](const Edge &a, const Edge &b) { return a.id < b.id; });
  for (int(i) = (0); (i) <= ((m)-1); (i)++) {
    if (ans[i] == -1) {
      int u = edges[i].u, v = edges[i].v;
      ans[i] = anc[u][0] == v ? mn[u][0] : mn[v][0];
    }
    printf("%d\n", ans[i]);
  }
}
