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>
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
using namespace ::std;
const int maxn = 1e5 + 500;
const int maxm = 1e6 + 5;
const int inf = 1e9;
const int logg = 18;
vector<int> tree[maxn];
int par[maxn];
int st[maxn];
int et[maxn];
int tt = 0;
bitset<maxm> inTree;
int jad[logg][maxn];
int mxx[logg][maxn];
int s[maxm];
int t[maxm];
int w[maxm];
int ans[maxm];
pair<int, int> r[maxm];
int findPar(int a) {
  if (par[a] == a) return a;
  par[a] = findPar(par[a]);
  return par[a];
}
void smax(int &a, int b) { a = max(a, b); }
void smin(int &a, int b) { a = min(a, b); }
void dfs(int a, int p = 0) {
  st[a] = tt++;
  jad[0][a] = p;
  for (int i = 1; i < logg; i++) {
    jad[i][a] = jad[i - 1][jad[i - 1][a]];
    mxx[i][a] = max(mxx[i - 1][a], mxx[i - 1][jad[i - 1][a]]);
  }
  for (auto e : tree[a]) {
    int v = (s[e] ^ t[e] ^ a);
    if (v != p) {
      mxx[0][v] = w[e];
      dfs(v, a);
    }
  }
  et[a] = tt++;
}
bool is_par(int a, int b) { return (st[a] <= st[b] && et[b] <= et[a]); }
int lca(int a, int b) {
  if (is_par(a, b)) return a;
  if (is_par(b, a)) return b;
  for (int i = logg - 1; i >= 0; i--) {
    if (!is_par(jad[i][a], b)) a = jad[i][a];
  }
  return jad[0][a];
}
int okKon(int a, int lc, int w, bool er) {
  int ans = 0;
  for (int i = logg - 1; i >= 0; i--) {
    if (!is_par(jad[i][a], lc)) {
      if (er)
        smax(ans, mxx[i][a]);
      else
        smin(mxx[i][a], w);
      a = jad[i][a];
    }
  }
  while (a != lc) {
    if (er)
      smax(ans, mxx[0][a]);
    else
      smin(mxx[0][a], w);
    a = jad[0][a];
  }
  return ans;
}
int findMax(int a, int b, int w, bool er) {
  int lc = lca(a, b);
  return max(okKon(a, lc, w, er), okKon(b, lc, w, er));
}
int 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++) {
    cin >> s[i] >> t[i] >> w[i];
    s[i]--;
    t[i]--;
    r[i] = make_pair(w[i], i);
  }
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
  sort(r, r + m);
  for (int i = 0; i < m; i++) {
    int e = r[i].second;
    int v = findPar(s[e]);
    int u = findPar(t[e]);
    if (u != v) {
      par[v] = u;
      tree[s[e]].push_back(e);
      tree[t[e]].push_back(e);
      inTree[e] = 1;
    }
  }
  dfs(0);
  for (int i = 0; i < m; i++) {
    if (inTree[i] == 0) {
      ans[i] = findMax(s[i], t[i], w[i], 1);
    }
  }
  for (int i = 0; i < maxn; i++) {
    for (int j = 0; j < logg; j++) mxx[j][i] = inf;
  }
  for (int i = 0; i < m; i++) {
    if (inTree[i] == 0) {
      findMax(s[i], t[i], w[i], 0);
    }
  }
  for (int i = logg - 1; i > 0; i--) {
    for (int j = 0; j < n; j++) {
      smin(mxx[i - 1][j], mxx[i][j]);
      smin(mxx[i - 1][jad[i - 1][j]], mxx[i][j]);
    }
  }
  for (int i = 0; i < m; i++) {
    if (inTree[i]) {
      if (is_par(s[i], t[i])) swap(s[i], t[i]);
      ans[i] = mxx[0][s[i]];
    }
  }
  for (int i = 0; i < m; i++) {
    smin(ans[i], inf);
    cout << ans[i] << endl;
    ;
  }
}
