#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
const long long INFLL = 1e18;
const int MAX_N = 100000;
const int MAX_M = 1000000;
const int MAX_K = 20;
int N, M;
vector<pair<int, int> > gp[MAX_N + 1];
int ans[MAX_M + 1];
struct Edge {
  int a, b, c, idx;
  bool operator<(const Edge &x) const {
    if (c == x.c) return idx < x.idx;
    return c < x.c;
  }
};
vector<Edge> edge;
int g[MAX_N + 1];
void ig() {
  for (int i = 1; i <= N; i++) g[i] = i;
}
int fg(int x) { return (x == g[x]) ? x : g[x] = fg(g[x]); }
void ug(int x, int y) {
  x = fg(x);
  y = fg(y);
  g[x] = y;
}
int p[MAX_N + 1], lv[MAX_N + 1];
pair<int, int> up[MAX_N + 1][MAX_K + 1];
int c[MAX_N + 1];
bool chk[MAX_M + 1];
void dfs(int x) {
  for (int i = 1; i < MAX_K; i++) {
    up[x][i].first = up[up[x][i - 1].first][i - 1].first;
    up[x][i].second =
        max(up[up[x][i - 1].first][i - 1].second, up[x][i - 1].second);
  }
  for (pair<int, int> i : gp[x]) {
    if (i.first == p[x]) continue;
    p[i.first] = x;
    lv[i.first] = lv[x] + 1;
    up[i.first][0] = {x, i.second};
    dfs(i.first);
  }
}
int Mx(int x, int y) {
  int ret = 0;
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (lv[up[x][i].first] >= lv[y]) {
      ret = max(ret, up[x][i].second);
      x = up[x][i].first;
    }
    if (lv[up[y][i].first] >= lv[x]) {
      ret = max(ret, up[y][i].second);
      y = up[y][i].first;
    }
  }
  if (x == y) return ret;
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (up[x][i].first != up[y][i].first) {
      ret = max(ret, max(up[x][i].second, up[y][i].second));
      x = up[x][i].first;
      y = up[y][i].first;
    }
  }
  ret = max(ret, max(up[x][0].second, up[y][0].second));
  return ret;
}
int lca(int x, int y) {
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (lv[up[x][i].first] >= lv[y]) {
      x = up[x][i].first;
    }
    if (lv[up[y][i].first] >= lv[x]) {
      y = up[y][i].first;
    }
  }
  if (x == y) return x;
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (up[x][i].first != up[y][i].first) {
      x = up[x][i].first;
      y = up[y][i].first;
    }
  }
  return up[x][0].first;
}
void check(int x, int y, int z) {
  x = fg(x);
  while (lv[x] > lv[y]) {
    c[x] = z;
    int tmp = x;
    ug(x, y);
    x = fg(p[x]);
  }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    edge.push_back({a, b, c, i});
    ans[i] = INF;
  }
  sort(edge.begin(), edge.end());
  ig();
  for (int i = 0; i < edge.size(); i++) {
    if (fg(edge[i].a) != fg(edge[i].b)) {
      ug(edge[i].a, edge[i].b);
      gp[edge[i].a].push_back({edge[i].b, edge[i].c});
      gp[edge[i].b].push_back({edge[i].a, edge[i].c});
      chk[i] = true;
    }
  }
  lv[1] = 1;
  dfs(1);
  ig();
  for (int i = 1; i <= N; i++) c[i] = INF;
  for (int i = 0; i < edge.size(); i++) {
    if (chk[i]) continue;
    ans[edge[i].idx] = Mx(edge[i].a, edge[i].b);
    int l = lca(edge[i].a, edge[i].b);
    check(edge[i].a, l, edge[i].c);
    check(edge[i].b, l, edge[i].c);
  }
  for (int i = 0; i < edge.size(); i++) {
    if (!chk[i]) continue;
    if (p[edge[i].a] == edge[i].b) {
      ans[edge[i].idx] = c[edge[i].a];
    } else {
      ans[edge[i].idx] = c[edge[i].b];
    }
  }
  for (int i = 1; i <= M; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
