#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, w, id;
} edge[1000005];
vector<pair<int, int> > G[100005], ans;
int n, m;
int fa[100005], dep[100005], now[100005];
int f[100005][21], w[100005][21];
bool vis[1000005];
bool cmp(node x, node y) { return x.w < y.w; }
void makeSet() {
  for (int i = 1; i <= n; i++) fa[i] = i;
}
int find(int x) { return (x == fa[x]) ? x : fa[x] = find(fa[x]); }
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  for (int i = 1; i <= 20; i++) {
    f[u][i] = f[f[u][i - 1]][i - 1];
    w[u][i] = max(w[u][i - 1], w[f[u][i - 1]][i - 1]);
  }
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i].first;
    if (v == fa) continue;
    f[v][0] = u, w[v][0] = G[u][i].second;
    dfs(v, u);
  }
}
pair<int, int> lca(int u, int v) {
  int maxx = 0;
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 20; ~i; i--)
    if (dep[f[u][i]] >= dep[v]) maxx = max(maxx, w[u][i]), u = f[u][i];
  if (u == v) return make_pair(maxx, u);
  for (int i = 20; ~i; i--)
    if (f[u][i] != f[v][i]) {
      maxx = max(maxx, w[u][i]);
      maxx = max(maxx, w[v][i]);
      u = f[u][i], v = f[v][i];
    }
  return make_pair(max(maxx, max(w[u][0], w[v][0])), f[u][0]);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].w);
    edge[i].id = i;
  }
  sort(edge + 1, edge + m + 1, cmp);
  makeSet();
  for (int i = 1; i <= m; i++) {
    int u = edge[i].u, v = edge[i].v, w = edge[i].w;
    int fu = find(u), fv = find(v);
    if (fu == fv) continue;
    vis[i] = 1;
    fa[fu] = fv;
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }
  dfs(1, 0);
  makeSet();
  for (int i = 1; i <= n; i++) now[i] = 1000000000;
  for (int i = 1; i <= m; i++) {
    int u = edge[i].u, v = edge[i].v, w = edge[i].w;
    if (!vis[i]) {
      pair<int, int> t = lca(u, v);
      ans.push_back(make_pair(edge[i].id, t.first));
      while (dep[find(u)] > dep[t.second]) {
        int fu = find(u);
        now[fu] = w;
        fa[fu] = find(f[fu][0]);
      }
      while (dep[find(v)] > dep[t.second]) {
        int fv = find(v);
        now[fv] = w;
        fa[fv] = find(f[fv][0]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (!vis[i]) continue;
    int u = edge[i].u, v = edge[i].v;
    if (dep[u] < dep[v]) swap(u, v);
    ans.push_back(make_pair(edge[i].id, now[u]));
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) printf("%d\n", ans[i].second);
  return 0;
}
