#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, w, used = 0, id;
  bool operator<(const Edge &e) const { return w < e.w; }
};
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<Edge> e(m + 1);
  for (int i = 1; i <= m; i++)
    scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w), e[i].id = i;
  sort(e.begin() + 1, e.end());
  vector<int> father(n + 1);
  iota(father.begin(), father.end(), 0);
  function<int(int)> find = [&](int n) {
    return father[n] == n ? n : father[n] = find(father[n]);
  };
  vector<vector<pair<int, int>>> v(n + 1);
  for (int i = 1; i <= m; i++) {
    int fax = find(e[i].u), fay = find(e[i].v);
    if (fax == fay) continue;
    father[fax] = fay;
    e[i].used = 1;
    v[e[i].u].emplace_back(e[i].v, e[i].w);
    v[e[i].v].emplace_back(e[i].u, e[i].w);
  }
  vector<int> depth(n + 1);
  vector<vector<int>> fa(n + 1, vector<int>(18));
  vector<vector<int>> ma(n + 1, vector<int>(18));
  function<void(int, int, int)> dfs = [&](int u, int f, int w) {
    depth[u] = depth[f] + 1;
    fa[u][0] = f;
    ma[u][0] = w;
    for (int i = 1; i <= 17; i++) {
      fa[u][i] = fa[fa[u][i - 1]][i - 1];
      ma[u][i] = max(ma[u][i - 1], ma[fa[u][i - 1]][i - 1]);
    }
    for (auto it : v[u])
      if (it.first != f) dfs(it.first, u, it.second);
  };
  dfs(1, 0, 0);
  vector<int> id(n + 1);
  for (int i = 1; i <= m; i++) {
    if (!e[i].used) continue;
    int a = e[i].u, b = e[i].v;
    if (fa[a][0] != b) swap(a, b);
    id[a] = e[i].id;
  }
  auto get_lca_max = [&](int u, int v) -> pair<int, int> {
    int ans = 0;
    if (depth[u] < depth[v]) swap(u, v);
    for (int i = 17; i >= 0; i--)
      if (depth[fa[u][i]] >= depth[v]) ans = max(ans, ma[u][i]), u = fa[u][i];
    if (u == v) return {ans, u};
    for (int i = 17; i >= 0; i--) {
      if (fa[u][i] == fa[v][i]) continue;
      ans = max(ans, max(ma[u][i], ma[v][i]));
      u = fa[u][i], v = fa[v][i];
    }
    ans = max(ans, max(ma[u][0], ma[v][0]));
    return {ans, fa[u][0]};
  };
  vector<int> ans(m + 1, -1);
  iota(father.begin(), father.end(), 0);
  for (int i = 1; i <= m; i++) {
    if (e[i].used) continue;
    int a = e[i].u, b = e[i].v, w = e[i].w;
    pair<int, int> p = get_lca_max(a, b);
    ans[e[i].id] = p.first;
    int lca = p.second;
    while (depth[a] > depth[lca]) {
      if (ans[id[a]] == -1) ans[id[a]] = w, father[a] = find(fa[a][0]);
      a = find(a);
    }
    while (depth[b] > depth[lca]) {
      if (ans[id[b]] == -1) ans[id[b]] = w, father[b] = find(fa[b][0]);
      b = find(b);
    }
  }
  for (int i = 1; i <= m; i++)
    if (ans[i] == -1)
      printf("%d\n", (int)1e9);
    else
      printf("%d\n", ans[i]);
  return 0;
}
