#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
const int M = 1000050;
const int inf = 1e9 + 7;
const int L = 17;
struct DSU {
  int p[N];
  void init() {
    for (int i = 0; i < N; i++) p[i] = i;
  }
  DSU() { init(); }
  int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); }
  void Union(int x, int y) { p[Find(x)] = Find(y); }
} DS;
vector<pair<int, int>> E[N];
int par[N][L], mx[N][L], dep[N], my[N], w[M];
void DFS(int u, int p, int e) {
  par[u][0] = p;
  mx[u][0] = e;
  dep[u] = dep[p] + 1;
  for (int i = 1; i < L; i++) {
    par[u][i] = par[par[u][i - 1]][i - 1];
    mx[u][i] = max(mx[u][i - 1], mx[par[u][i - 1]][i - 1]);
  }
  for (auto ed : E[u])
    if (ed.first != p) {
      my[ed.first] = ed.second;
      DFS(ed.first, u, w[ed.second]);
    }
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = L - 1; ~i; i--)
    if (dep[par[u][i]] >= dep[v]) u = par[u][i];
  for (int i = L - 1; ~i; i--)
    if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
  return u == v ? v : par[v][0];
}
int u[M], v[M], id[M], ans[M];
void AddEdge(int u, int v, int w) {
  E[u].push_back({v, w});
  E[v].push_back({u, w});
}
vector<int> mst, nope;
int Get(int u, int lca) {
  int d = dep[u] - dep[lca], ans = 0;
  for (int i = 0; i < L; i++)
    if (d >> i & 1) ans = max(ans, mx[u][i]), u = par[u][i];
  return ans;
}
void Set(int u, int lca, int x) {
  int d = dep[u] - dep[lca];
  for (int i = 0; i < L; i++)
    if (d >> i & 1) mx[u][i] = min(mx[u][i], x), u = par[u][i];
}
void Clear() {
  for (int i = 0; i < L; i++)
    for (int j = 0; j < N; j++) mx[j][i] = inf;
}
void Push() {
  for (int j = L - 1; j; j--) {
    for (int i = 0; i < N; i++) {
      mx[i][j - 1] = min(mx[i][j - 1], mx[i][j]);
      mx[par[i][j - 1]][j - 1] = min(mx[par[i][j - 1]][j - 1], mx[i][j]);
    }
  }
}
int main() {
  int n, m;
  scanf("%i %i", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%i %i %i", &u[i], &v[i], &w[i]);
    id[i] = i;
  }
  sort(id + 1, id + 1 + m, [&](int i, int j) { return w[i] < w[j]; });
  for (int j = 1; j <= m; j++) {
    int i = id[j];
    if (DS.Find(u[i]) != DS.Find(v[i])) {
      AddEdge(u[i], v[i], i);
      mst.push_back(i);
      DS.Union(u[i], v[i]);
    } else
      nope.push_back(i);
  }
  DFS(1, 0, 0);
  for (int i : nope) {
    int lca = LCA(u[i], v[i]);
    ans[i] = max(Get(u[i], lca), Get(v[i], lca));
  }
  Clear();
  for (int i : nope) {
    int lca = LCA(u[i], v[i]);
    Set(u[i], lca, w[i]);
    Set(v[i], lca, w[i]);
  }
  Push();
  for (int i = 2; i <= n; i++) ans[my[i]] = mx[i][0];
  for (int i = 1; i <= m; i++) {
    if (ans[i] == inf)
      printf("1000000000\n");
    else
      printf("%i\n", ans[i]);
  }
  return 0;
}
