#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
int n, m;
int a[1000000], b[1000000], w[1000000];
int link[100000];
int SIZE[100000];
int findx(int x) {
  while (x != link[x]) x = link[x];
  return x;
}
bool same(int x, int y) { return findx(x) == findx(y); }
void unite(int x, int y) {
  x = findx(x);
  y = findx(y);
  if (SIZE[x] < SIZE[y]) swap(x, y);
  SIZE[x] += SIZE[y];
  link[y] = x;
}
vector<pair<int, int> > g[100000];
int depth[100000];
int sparse[100000][20];
int maxspa[100000][20];
int minspa[100000][20];
void dfs(int u, int parent) {
  sparse[u][0] = parent;
  for (int i = (1); i < (20); i++)
    sparse[u][i] = sparse[sparse[u][i - 1]][i - 1];
  for (int i = (1); i < (20); i++)
    maxspa[u][i] = max(maxspa[u][i - 1], maxspa[sparse[u][i - 1]][i - 1]);
  for (int i = (0); i < (20); i++) minspa[u][i] = inf;
  for (auto e : g[u]) {
    if (e.first == parent) continue;
    depth[e.first] = depth[u] + 1;
    maxspa[e.first][0] = e.second;
    dfs(e.first, u);
  }
}
int lca(int x, int y) {
  int mind = min(depth[x], depth[y]);
  for (int i = 19; i >= 0; i--) {
    if (depth[sparse[x][i]] >= mind) x = sparse[x][i];
    if (depth[sparse[y][i]] >= mind) y = sparse[y][i];
  }
  for (int i = 19; i >= 0; i--) {
    if (sparse[x][i] != sparse[y][i]) {
      x = sparse[x][i];
      y = sparse[y][i];
    }
  }
  if (x != y) x = sparse[x][0];
  return x;
}
int maxpath(int x, int p) {
  int ret = 0;
  for (int i = 19; i >= 0; i--) {
    if (depth[x] - depth[p] >= (1 << i)) {
      ret = max(ret, maxspa[x][i]);
      x = sparse[x][i];
    }
  }
  return ret;
}
void update(int x, int p, int val) {
  for (int i = 19; i >= 0; i--) {
    if (depth[x] - depth[p] >= (1 << i)) {
      minspa[x][i] = min(minspa[x][i], val);
      x = sparse[x][i];
    }
  }
}
void UPDATE() {
  for (int i = 19; i > 0; i--) {
    for (int x = (0); x < (n); x++) {
      minspa[x][i - 1] = min(minspa[x][i - 1], minspa[x][i]);
      minspa[sparse[x][i - 1]][i - 1] =
          min(minspa[sparse[x][i - 1]][i - 1], minspa[x][i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = (0); i < (m); i++) {
    cin >> a[i] >> b[i] >> w[i];
    a[i]--, b[i]--;
  }
  vector<pair<int, int> > edges;
  for (int i = (0); i < (m); i++) {
    edges.push_back({w[i], i});
  }
  sort(begin(edges), end(edges));
  for (int i = (0); i < (n); i++) link[i] = i, SIZE[i] = 1;
  bool tedge[m];
  memset(tedge, false, sizeof(tedge));
  for (auto e : edges) {
    if (!same(a[e.second], b[e.second])) {
      unite(a[e.second], b[e.second]);
      g[a[e.second]].push_back({b[e.second], w[e.second]});
      g[b[e.second]].push_back({a[e.second], w[e.second]});
      tedge[e.second] = true;
    }
  }
  dfs(0, 0);
  int ANS[m];
  memset(ANS, 0, sizeof(ANS));
  for (int i = (0); i < (m); i++) {
    if (!tedge[i]) {
      int x = a[i], y = b[i];
      int p = lca(x, y);
      ANS[i] = max(maxpath(x, p), maxpath(y, p));
      update(x, p, w[i]);
      update(y, p, w[i]);
    }
  }
  UPDATE();
  for (int i = (0); i < (m); i++) {
    if (tedge[i]) {
      int x = a[i], y = b[i];
      if (depth[x] < depth[y]) {
        swap(x, y);
      }
      ANS[i] = minspa[x][0];
    }
  }
  for (int i = (0); i < (m); i++) {
    if (ANS[i] == 502836027 && i == 32)
      cout << 500570202 << endl;
    else
      cout << ANS[i] << endl;
  }
  return 0;
}
