#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 1000010, LOG = 20;
int n, m, u[M], v[M], w[M];
int num = 0, a, b;
int dsu[N], dp[LOG][N], dp2[LOG][N], depth[N];
bool good[M];
int ans[M], l;
vector<pair<int, int> > arr;
vector<pair<int, int> > g[N];
vector<int> add[N], rem[N];
multiset<int> st[N];
int Find(int u) { return (u == dsu[u] ? u : dsu[u] = Find(dsu[u])); }
void DFS(int node) {
  for (int i = 0; i < (int)g[node].size(); i++) {
    if (g[node][i].first == dp[0][node]) continue;
    dp[0][g[node][i].first] = node;
    dp2[0][g[node][i].first] = w[g[node][i].second];
    depth[g[node][i].first] = depth[node] + 1;
    for (int k = 1; k < LOG; k++) {
      if (dp[k - 1][g[node][i].first] == -1)
        dp[k - 1][g[node][i].first] = -1;
      else {
        dp[k][g[node][i].first] = dp[k - 1][dp[k - 1][g[node][i].first]];
        dp2[k][g[node][i].first] = max(dp2[k - 1][g[node][i].first],
                                       dp2[k - 1][dp[k - 1][g[node][i].first]]);
      }
    }
    DFS(g[node][i].first);
  }
}
int getmax(int u, int v) {
  int mx = 0;
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = LOG - 1; k >= 0; k--) {
    if (depth[v] - (1 << k) >= depth[u]) {
      mx = max(mx, dp2[k][v]);
      v = dp[k][v];
    }
  }
  l = u;
  if (u == v) return mx;
  for (int k = LOG - 1; k >= 0; k--) {
    if (dp[k][u] != dp[k][v]) {
      mx = max(mx, dp2[k][v]);
      v = dp[k][v];
      mx = max(mx, dp2[k][u]);
      u = dp[k][u];
    }
  }
  mx = max(mx, max(dp2[0][u], dp2[0][v]));
  l = dp[0][u];
  return mx;
}
void DFS(int node, int pre) {
  int idx = -1, mx = 0;
  for (int i = 0; i < (int)g[node].size(); i++) {
    if (g[node][i].first == dp[0][node]) continue;
    DFS(g[node][i].first, g[node][i].second);
    if ((int)st[g[node][i].first].size() > mx) {
      mx = (int)st[g[node][i].first].size();
      idx = i;
    }
  }
  if (pre == -1) return;
  if (idx != -1) {
    swap(st[node], st[g[node][idx].first]);
  }
  for (int i = 0; i < (int)add[node].size(); i++) st[node].insert(add[node][i]);
  for (int i = 0; i < (int)g[node].size(); i++) {
    if (g[node][i].first == dp[0][node] || idx == i) continue;
    for (multiset<int>::iterator it = st[g[node][i].first].begin();
         it != st[g[node][i].first].end(); it++) {
      st[node].insert(*it);
    }
    st[g[node][i].first].clear();
  }
  for (int i = 0; i < (int)rem[node].size(); i++)
    st[node].erase(st[node].find(rem[node][i]));
  if ((int)st[node].size() == 0)
    ans[pre] = 1000000000;
  else
    ans[pre] = *st[node].begin();
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) dsu[i] = i;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    arr.push_back(make_pair(w[i], i));
  }
  sort(arr.begin(), arr.end());
  for (int i = 0; i < (int)arr.size(); i++) {
    a = Find(u[arr[i].second]);
    b = Find(v[arr[i].second]);
    if (a == b) continue;
    good[arr[i].second] = true;
    dsu[b] = a;
    g[u[arr[i].second]].push_back(make_pair(v[arr[i].second], arr[i].second));
    g[v[arr[i].second]].push_back(make_pair(u[arr[i].second], arr[i].second));
  }
  dp[0][1] = -1;
  DFS(1);
  for (int i = 0; i < m; i++) {
    if (good[i]) continue;
    ans[i] = getmax(u[i], v[i]);
    add[u[i]].push_back(w[i]);
    add[v[i]].push_back(w[i]);
    rem[l].push_back(w[i]);
    rem[l].push_back(w[i]);
  }
  DFS(1, -1);
  for (int i = 0; i < m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
