#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize 03
#pragma GCC optimize("unroll-loops")
using namespace std;
int gcd(int a, int b) { return (a == 0) ? b : gcd(b % a, a); }
int cnt1(int x) {
  int cnt = 0;
  while (x > 0) x &= x - 1, cnt++;
  return cnt;
}
int fact(int n) { return n == 0 ? 1LL : n * fact(n - 1); }
int fact(int n, int p) { return n == 0 ? 1LL : n * fact(n - 1) % p; }
int cnk(int n, int k) {
  return n == 1 || k == 1 ? 1 : cnk(n - 1, k) + cnk(n - 1, k - 1);
}
int pow(int a, int n, int p) {
  if (n == 0) return 1;
  long long t = pow(a, n >> 1, p);
  return t * t % p * (n & 1 ? a : 1) % p;
}
int back(int x, int p) { return pow(x, p - 2, p); }
int cnk(int n, int k, int p) {
  return fact(n, p) * back(fact(k, p), p) % p * back(fact(n - k, p), p) % p;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
istream &operator>>(istream &stream, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) stream >> v[i];
  return stream;
}
template <class T>
ostream &operator<<(ostream &stream, vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) stream << v[i] << ' ';
  stream << '\n';
  return stream;
}
const int N = 1e+5 + 1;
int p[N];
int find_p(int v) {
  if (p[v] == v)
    return v;
  else
    return p[v] = find_p(p[v]);
}
bool union_set(int a, int b) {
  a = find_p(a);
  b = find_p(b);
  if (a == b) return 0;
  if (rnd() & 1)
    p[a] = b;
  else
    p[b] = a;
  return 1;
}
vector<pair<pair<int, int>, pair<int, int>>> e;
vector<pair<int, int>> gr[N];
const int M = 1e+6;
int ans[M];
bool in_mst[M];
set<pair<int, int>> s[N];
int ns[N];
int tin[N], tout[N], timer;
void dfs(int v, int p = -1, int laste = -1) {
  tin[v] = timer++;
  int mx = v, umx = v;
  for (auto x : gr[v]) {
    int u = x.first, ne = x.second;
    if (u != p) {
      if (in_mst[ne]) {
        dfs(u, v, e[ne].first.second);
        if (s[ns[u]].size() > s[mx].size()) mx = ns[u], umx = u;
      } else
        s[v].insert({e[ne].first.first, u});
    }
  }
  tout[v] = timer;
  if (s[v].size() > s[mx].size()) mx = v, umx = v;
  ns[v] = mx;
  for (auto x : gr[v]) {
    int u = x.first, ne = x.second;
    if (u != p && u != umx)
      if (in_mst[ne]) {
        for (auto t : s[ns[u]]) s[mx].insert(t);
        s[ns[u]].clear();
      }
  }
  if (mx != v) {
    for (auto t : s[v]) s[mx].insert(t);
    s[v].clear();
  }
  while (s[mx].size() && tin[v] <= tin[s[mx].begin()->second] &&
         tin[s[mx].begin()->second] < tout[v])
    s[mx].erase(s[mx].begin());
  if (laste != -1)
    if (s[mx].size() == 0)
      ans[laste] = 1e+9;
    else
      ans[laste] = s[mx].begin()->first;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    e.push_back({{c, i}, {a, b}});
  }
  vector<int> l(m), r(m);
  for (int i = 0; i < m; i++) r[i] = m;
  sort(e.begin(), e.end());
  for (int t = 0; t < 20; t++) {
    vector<pair<int, int>> q(m);
    for (int i = 0; i < m; i++) q[i] = {(l[i] + r[i]) >> 1, i};
    sort(q.begin(), q.end());
    for (int i = 0; i < n; i++) p[i] = i;
    int i, j = 0;
    for (i = 0; i < m; i++) {
      if (union_set(e[i].second.first, e[i].second.second)) in_mst[i] = 1;
      while (j < m && q[j].first == i) {
        if (find_p(e[q[j].second].second.first) ==
            find_p(e[q[j].second].second.second))
          r[q[j].second] = i;
        else
          l[q[j].second] = i;
        j++;
      }
    }
  }
  for (int i = 0; i < m; i++)
    if (!in_mst[i]) ans[e[i].first.second] = e[l[i] + 1].first.first;
  for (int i = 0; i < m; i++) {
    gr[e[i].second.first].push_back({e[i].second.second, i});
    gr[e[i].second.second].push_back({e[i].second.first, i});
  }
  dfs(0);
  for (int i = 0; i < m; i++) cout << ans[i] << '\n';
}
