#include <bits/stdc++.h>
using namespace std;
class UnionFind {
  vector<int> par, sz;

 public:
  UnionFind() {}
  UnionFind(int n) {
    par = sz = vector<int>(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sz[x] > sz[y]) {
      par[y] = x;
      sz[x] += sz[y];
    } else {
      par[x] = y;
      sz[y] += sz[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sz[find(x)]; }
};
vector<int> E[100000];
bool used[100000];
int par[18][100000], d[100000];
int ans2[100000];
void dfs(int v, int p, int depth) {
  used[v] = true;
  d[v] = depth;
  par[0][v] = p;
  for (int u : E[v]) {
    if (used[u]) continue;
    dfs(u, v, depth + 1);
  }
}
void lca_init(int n) {
  for (int i = 1; i < 18; i++)
    for (int j = 0; j < (n); j++) {
      if (par[i - 1][j] == -1) par[i][j] = -1;
      par[i][j] = par[i - 1][par[i - 1][j]];
    }
}
int lca(int u, int v) {
  if (d[u] < d[v]) swap(u, v);
  for (int i = 0; i < (18); i++) {
    if ((d[u] - d[v]) >> i & 1) u = par[i][u];
  }
  if (u == v) return u;
  for (int i = 17; i >= 0; i--) {
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  }
  return par[0][u];
}
struct UF2 {
  vector<int> pa;
  UF2(int n) {
    pa = vector<int>(n);
    for (int i = 0; i < (n); i++) pa[i] = i;
  }
  int find(int x) {
    if (pa[x] == x) return x;
    return pa[x] = find(pa[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    pa[x] = y;
  }
  void climb(int v, int p, int col) {
    while (1) {
      v = find(v);
      if (d[v] <= d[p]) break;
      ans2[v] = col;
      unite(v, par[0][v]);
    }
  }
};
int n, m;
struct st {
  int a, b, c, id;
};
vector<st> es;
vector<pair<int, int> > query[100001];
int ok[1000000], ng[1000000];
int a[1000000], b[1000000], c[1000000];
int ans[1000000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    a[i]--;
    b[i]--;
    es.push_back({a[i], b[i], c[i], i});
  }
  sort(es.begin(), es.end(), [](st a, st b) { return a.c < b.c; });
  UnionFind uf(n);
  vector<st> vs;
  vector<st> us;
  for (auto s : es) {
    if (uf.same(s.a, s.b)) {
      vs.push_back(s);
    } else {
      uf.unite(s.a, s.b);
      us.push_back(s);
    }
  }
  for (auto s : us) {
    E[s.a].push_back(s.b);
    E[s.b].push_back(s.a);
  }
  dfs(0, -1, 0);
  lca_init(n);
  memset(ans2, -1, sizeof(ans2));
  UF2 uf2(n);
  for (auto s : vs) {
    int p = lca(s.a, s.b);
    uf2.climb(s.a, p, s.c);
    uf2.climb(s.b, p, s.c);
  }
  for (auto s : vs) {
    ok[s.id] = 0;
    ng[s.id] = us.size() + 1;
  }
  for (int loop = 0; loop < (25); loop++) {
    for (int i = 0; i < (us.size() + 1); i++) {
      query[i].clear();
    }
    for (auto s : vs) {
      int t = (ok[s.id] + ng[s.id]) / 2;
      query[t].push_back(pair<int, int>(t, s.id));
    }
    UnionFind uf(n);
    for (int i = 0; i < (us.size() + 1); i++) {
      for (auto p : query[i]) {
        if (uf.same(a[p.second], b[p.second]))
          ng[p.second] = i;
        else
          ok[p.second] = i;
      }
      if (i < us.size()) {
        uf.unite(us[i].a, us[i].b);
      }
    }
  }
  memset(ans, -1, sizeof(ans));
  for (auto s : vs) {
    ans[s.id] = (ok[s.id] == us.size() ? 1e9 : us[ok[s.id]].c);
  }
  for (int i = 0; i < (m); i++) {
    if (ans[i] != -1) {
      printf("%d\n", ans[i]);
    } else {
      if (d[a[i]] < d[b[i]]) swap(a[i], b[i]);
      if (ans2[a[i]] == -1) {
        puts("1000000000");
      } else
        printf("%d\n", ans2[a[i]]);
    }
  }
}
