#include <bits/stdc++.h>
using namespace std;
namespace ufs {
int fa[100005];
void makeset(int n) {
  for (int i = 1; i <= n; i++) fa[i] = i;
}
int findset(int x) {
  if (fa[x] == x) return x;
  return fa[x] = findset(fa[x]);
}
void merge(int u, int v) {
  int a = findset(u);
  int b = findset(v);
  fa[a] = b;
}
}  // namespace ufs
using namespace ufs;
struct edge {
  int u, v;
  long long w;
  int id;
  friend bool operator<(const edge &a, const edge &b) { return a.w < b.w; }
} a[1000005];
struct node {
  int e;
  long long w;
};
int n, m;
int dep[100005], w[100005], fath[100005];
int dp_ind[100005][25];
long long dp_max[100005][25];
long long ans[1000005];
bool vis[1000005];
vector<node> g[100005];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  for (int i = 1; i <= 20; i++) {
    dp_ind[u][i] = dp_ind[dp_ind[u][i - 1]][i - 1];
    dp_max[u][i] = max(dp_max[u][i - 1], dp_max[dp_ind[u][i - 1]][i - 1]);
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].e;
    if (v != fa) {
      dp_ind[v][0] = u;
      dp_max[v][0] = g[u][i].w;
      fath[v] = u;
      dfs(v, u);
    }
  }
}
long long lca(int u, int v) {
  long long maxx = 0;
  if (u == v) return 0;
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = 20; i >= 0; i--)
    if (dep[u] <= dep[dp_ind[v][i]]) {
      maxx = max(maxx, dp_max[v][i]);
      v = dp_ind[v][i];
    }
  if (u == v) return maxx;
  for (int i = 20; i >= 0; i--)
    if (dp_ind[u][i] != dp_ind[v][i]) {
      maxx = max(maxx, max(dp_max[u][i], dp_max[v][i]));
      u = dp_ind[u][i];
      v = dp_ind[v][i];
    }
  return max(maxx, max(dp_max[u][0], dp_max[v][0]));
}
void col(int u, int v, long long s) {
  while (u != v) {
    if (dep[u] > dep[v]) swap(u, v);
    w[v] = s;
    merge(v, fath[v]);
    v = findset(v);
  }
}
int main() {
  memset(ans, -1, sizeof(ans));
  memset(w, -1, sizeof(w));
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i].u >> a[i].v >> a[i].w;
    a[i].id = i;
  }
  sort(a + 1, a + m + 1);
  makeset(n);
  for (int i = 1; i <= m; i++) {
    if (findset(a[i].u) != findset(a[i].v)) {
      vis[i] = 1;
      merge(a[i].u, a[i].v);
      g[a[i].u].push_back((node){a[i].v, a[i].w});
      g[a[i].v].push_back((node){a[i].u, a[i].w});
    }
  }
  dfs(1, 0);
  for (int i = 1; i <= m; i++)
    if (dep[a[i].u] > dep[a[i].v]) swap(a[i].u, a[i].v);
  makeset(n);
  for (int i = 1; i <= m; i++)
    if (vis[i] == 0) col(findset(a[i].u), findset(a[i].v), a[i].w);
  for (int i = 1; i <= m; i++) {
    if (vis[i] == 0)
      ans[a[i].id] = lca(a[i].u, a[i].v);
    else
      ans[a[i].id] = w[a[i].v];
  }
  for (int i = 1; i <= m; i++) {
    if (ans[i] == -1)
      cout << 1000000000;
    else
      cout << ans[i];
    cout << '\n';
  }
  return 0;
}
