With your help, Heidi has prepared a plan of trap placement and defence. Yet suddenly, the Doctor popped out of the TARDIS and told her that he had spied on the Daleks' preparations, and there is more of them than ever. Desperate times require desperate measures, so Heidi is going to risk meeting with the Daleks and she will consider placing a trap along any Corridor.

This means she needs your help again in calculating E_{max}(c) – the largest e ≤ 10^9 such that if we changed the energy requirement of c to e, then the Daleks might use c in their invasion – but this time for all Time Corridors.

Input

First line: number n of destinations, number m of corridors (2 ≤ n ≤ 10^5, n - 1 ≤ m ≤ 10^6). The next m lines: destinations a, b and energy e (1 ≤ a, b ≤ n, a ≠ b, 0 ≤ e ≤ 10^9).

No pair \\{a, b\} will repeat. The graph is guaranteed to be connected. It is not guaranteed that all energy requirements e are distinct, or that the minimum spanning tree is unique.

Output

Output m lines, each containing one integer: E_{max}(c_i) for the i-th Corridor c_i from the input.

Example

Input

3 3
1 2 8
2 3 3
3 1 4


Output

4
8
8
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &first, T2 second) {
  if (first > second) first = second;
}
template <typename T1, typename T2>
inline void chkmax(T1 &first, T2 second) {
  if (first < second) first = second;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second;
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
const int N = 1e5 + 5;
int n, m;
int dsu[N], h[N];
vector<pair<int, int>> edge[N];
vector<pair<int, int>> bedge[N];
vector<pair<int, pair<int, int>>> edges, v;
set<pair<int, int>> used;
map<pair<int, int>, int> ans;
int get(int i) { return i == dsu[i] ? i : dsu[i] = get(dsu[i]); }
bool merge(int i, int j) {
  i = get(i);
  j = get(j);
  if (i == j) return false;
  dsu[i] = j;
  return true;
}
const int LOG = 18;
int t;
int tin[N], tout[N];
pair<int, int> up[LOG][N];
int bad[LOG][N];
void dfs(int i, int p = -1) {
  tin[i] = t++;
  for (auto j : edge[i]) {
    if (j.first == p) continue;
    up[0][j.first] = {i, j.second};
    h[j.first] = h[i] + 1;
    dfs(j.first, i);
  }
  tout[i] = t++;
}
bool is_parent(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }
int lca(int a, int b, int v) {
  int ans = 0;
  for (int t = 0; t < 2; ++t) {
    if (tin[a] > tin[b]) swap(a, b);
    if (!is_parent(b, a)) {
      for (int t = LOG; t--;) {
        int c = up[t][b].first;
        if (!is_parent(c, a)) {
          chkmax(ans, up[t][b].second);
          chkmin(bad[t][b], v);
          b = c;
        }
      }
      chkmax(ans, up[0][b].second);
      chkmin(bad[0][b], v);
      b = up[0][b].first;
    }
    assert(is_parent(b, a));
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  srand(time(0));
  cin >> n >> m;
  edges.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first;
  }
  v = edges;
  sort(edges.begin(), edges.end());
  bool was = false;
  for (int i = 0; i <= n; ++i) dsu[i] = i;
  for (auto i : edges) {
    if (merge(i.second.first, i.second.second)) {
      used.insert(i.second);
      edge[i.second.first].push_back({i.second.second, i.first});
      edge[i.second.second].push_back({i.second.first, i.first});
    } else {
      bedge[i.second.first].push_back({i.second.second, i.first});
      bedge[i.second.second].push_back({i.second.first, i.first});
    }
  }
  up[0][1] = {1, 0};
  dfs(1);
  for (int t = 0; t < LOG; ++t) {
    for (int i = 1; i <= n; ++i) {
      bad[t][i] = 1e9;
    }
  }
  for (int t = 0; t + 1 < LOG; ++t) {
    for (int i = 1; i <= n; ++i) {
      up[t + 1][i] = {up[t][up[t][i].first].first,
                      max(up[t][i].second, up[t][up[t][i].first].second)};
    }
  }
  for (auto i : v) {
    if (used.count(i.second)) {
      continue;
    }
    ans[i.second] = lca(i.second.first, i.second.second, i.first);
  }
  for (int t = LOG - 1; t--;) {
    for (int i = 1; i <= n; ++i) {
      int j = up[t][i].first;
      chkmin(bad[t][i], bad[t + 1][i]);
      chkmin(bad[t][j], bad[t + 1][i]);
    }
  }
  for (int i = 2; i <= n; ++i) {
    int j = up[0][i].first;
    ans[{i, j}] = ans[{j, i}] = bad[0][i];
  }
  for (auto i : v) {
    cout << ans[i.second] << '\n';
  }
}
