#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, k, s, t, fa[N], log2n, h[N * 10], de[N], size[N], son[N];
int f[N][20], g[N][20], pre[N], ans[N * 10];
struct node1 {
  int x, y, v, id;
  bool operator<(const node1 &k) const { return v < k.v; }
} a[N * 10];
struct node {
  int x, v, id;
};
vector<node> e[N];
void dfs(int u, int p) {
  size[u] = 1;
  for (auto &i : e[u]) {
    if (i.x != p) {
      de[i.x] = de[u] + 1;
      f[i.x][0] = u;
      g[i.x][0] = i.v;
      pre[i.x] = i.id;
      dfs(i.x, u);
      size[u] += size[i.x];
      if (size[son[u]] < size[i.x]) son[u] = i.x;
    }
  }
}
int calc(int u, int x) {
  int xx = 0, o = 0;
  for (; x; x >>= 1) {
    if (x & 1) {
      xx = max(xx, g[u][o]);
      u = f[u][o];
    }
    ++o;
  }
  return xx;
}
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
int lca(int u, int v) {
  if (de[u] < de[v]) swap(u, v);
  for (int o = 0, k = de[u] - de[v]; k; k >>= 1) {
    if (k & 1) u = f[u][o];
    ++o;
  }
  if (u == v) return u;
  for (int j = log2n; j >= 0; --j)
    if (f[u][j] != f[v][j]) {
      u = f[u][j];
      v = f[v][j];
    }
  return f[u][0];
}
vector<pair<int, int>> b[N];
map<int, int> ma;
void add(int u, int p, int x) {
  for (auto &i : e[u]) {
    if (i.x != p && i.x != x) {
      add(i.x, u, x);
    }
  }
  for (auto &i : b[u])
    if (ma[i.first] + i.second == 0)
      ma.erase(i.first);
    else
      ma[i.first] += i.second;
}
void dfs1(int u, int p, int opt) {
  for (auto &i : e[u]) {
    if (i.x != son[u] && i.x != p) {
      dfs1(i.x, u, 0);
    }
  }
  if (son[u]) dfs1(son[u], u, 1);
  add(u, p, son[u]);
  if (u != 1) {
    if (ma.empty())
      ans[pre[u]] = 1000000000;
    else
      ans[pre[u]] = ma.begin()->first;
  }
  if (!opt) ma.clear();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i].x >> a[i].y >> a[i].v;
    a[i].id = i;
  }
  sort(a + 1, a + 1 + m);
  iota(fa + 1, fa + 1 + n, 1);
  for (int i = 1; i <= m; ++i) {
    s = getfa(a[i].x);
    t = getfa(a[i].y);
    if (s != t) {
      fa[s] = t;
      h[i] = 1;
      e[a[i].y].push_back({a[i].x, a[i].v, a[i].id});
      e[a[i].x].push_back({a[i].y, a[i].v, a[i].id});
    }
  }
  dfs(1, 0);
  log2n = log2(n);
  for (int j = 1; j <= log2n; ++j)
    for (int i = 1; i <= n; ++i) {
      g[i][j] = max(g[i][j - 1], g[f[i][j - 1]][j - 1]);
      f[i][j] = f[f[i][j - 1]][j - 1];
    }
  for (int i = 1; i <= m; ++i)
    if (!h[i]) {
      k = lca(a[i].x, a[i].y);
      ans[a[i].id] = max(calc(a[i].x, de[a[i].x] - de[k]),
                         calc(a[i].y, de[a[i].y] - de[k]));
      b[a[i].x].push_back({a[i].v, 1});
      b[a[i].y].push_back({a[i].v, 1});
      b[k].push_back({a[i].v, -2});
    }
  dfs1(1, 0, 1);
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
