#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *l = buf, *r = buf;
  return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r)
             ? EOF
             : *l++;
}
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = nc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = nc();
  }
  x *= f;
}
const int inf = 1e9;
const int maxn = 1e5 + 5;
const int maxm = 1e6 + 5;
int n, m;
int dfc;
int anc[maxn];
int dep[maxn];
int dfn[maxn];
int rnk[maxn];
int siz[maxn];
int son[maxn];
int top[maxn];
int val[maxn];
int head[maxn];
struct edge {
  int to, nex, cost;
  edge(int to = 0, int nex = 0, int cost = 0) : to(to), nex(nex), cost(cost) {}
};
vector<edge> G;
inline void addedge(int u, int v, int w) {
  G.push_back(edge(v, head[u], w)), head[u] = G.size() - 1;
  G.push_back(edge(u, head[v], w)), head[v] = G.size() - 1;
}
struct data {
  int a, b, e;
  int id;
  inline bool operator<(const data &other) const { return e < other.e; }
} e[maxm];
inline int cmp(const data &a, const data &b) { return a.id < b.id; }
namespace us {
int fa[maxn];
void init(int n) {
  for (int i = 1; i <= n; ++i) fa[i] = i;
}
int find(int a) { return a == fa[a] ? a : fa[a] = find(fa[a]); }
bool merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return 0;
  fa[a] = b;
  return 1;
}
}  // namespace us
namespace seg {
int tag[maxn << 2];
int mxv[maxn << 2];
inline void pushup(int u) { mxv[u] = max(mxv[u << 1], mxv[u << 1 | 1]); }
inline void change(int u, int d) { tag[u] = min(tag[u], d); }
inline void pushdown(int u) {
  if (tag[u] != inf) {
    change(u << 1, tag[u]);
    change(u << 1 | 1, tag[u]);
    tag[u] = inf;
  }
}
void build(int u, int l, int r) {
  tag[u] = inf;
  if (l == r) {
    mxv[u] = val[rnk[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build(u << 1, l, mid);
  build(u << 1 | 1, mid + 1, r);
  pushup(u);
}
void update(int u, int l, int r, int ql, int qr, int qv) {
  if (l == ql && r == qr) {
    change(u, qv);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(u);
  if (qr <= mid)
    update(u << 1, l, mid, ql, qr, qv);
  else if (ql > mid)
    update(u << 1 | 1, mid + 1, r, ql, qr, qv);
  else {
    update(u << 1, l, mid, ql, mid, qv);
    update(u << 1 | 1, mid + 1, r, mid + 1, qr, qv);
  }
}
int Qmin(int u, int l, int r, int qp) {
  if (l == r) {
    return tag[u];
  }
  int mid = (l + r) >> 1;
  pushdown(u);
  if (qp <= mid)
    return Qmin(u << 1, l, mid, qp);
  else
    return Qmin(u << 1 | 1, mid + 1, r, qp);
}
int Qmax(int u, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) {
    return mxv[u];
  }
  int mid = (l + r) >> 1;
  if (qr <= mid)
    return Qmax(u << 1, l, mid, ql, qr);
  else if (ql > mid)
    return Qmax(u << 1 | 1, mid + 1, r, ql, qr);
  else {
    int L = Qmax(u << 1, l, mid, ql, mid);
    int R = Qmax(u << 1 | 1, mid + 1, r, mid + 1, qr);
    return max(L, R);
  }
}
}  // namespace seg
void update(int u, int v, int w) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    seg ::update(1, 1, n, dfn[top[u]], dfn[u], w);
    u = anc[top[u]];
  }
  if (dep[u] < dep[v]) swap(u, v);
  if (u != v) seg ::update(1, 1, n, dfn[v] + 1, dfn[u], w);
}
int query(int u, int v) {
  int re = 0;
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    re = max(re, seg ::Qmax(1, 1, n, dfn[top[u]], dfn[u]));
    u = anc[top[u]];
  }
  if (dep[u] < dep[v]) swap(u, v);
  if (u != v) re = max(re, seg ::Qmax(1, 1, n, dfn[v] + 1, dfn[u]));
  return re;
}
void dfs1(int u) {
  siz[u] = 1;
  for (int i = head[u]; ~i; i = G[i].nex) {
    int v = G[i].to;
    if (v == anc[u]) continue;
    anc[v] = u;
    val[v] = G[i].cost;
    dep[v] = dep[u] + 1;
    dfs1(v);
    siz[u] += siz[v];
    if (siz[v] >= siz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int chain) {
  top[u] = chain;
  dfn[u] = ++dfc;
  rnk[dfc] = u;
  if (son[u]) {
    dfs2(son[u], chain);
  }
  for (int i = head[u]; ~i; i = G[i].nex) {
    int v = G[i].to;
    if (v == son[u] || v == anc[u]) continue;
    dfs2(v, v);
  }
}
void kruskal() {
  us ::init(n);
  sort(e + 1, e + m + 1);
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= m; ++i) {
    if (us ::merge(e[i].a, e[i].b)) {
      addedge(e[i].a, e[i].b, e[i].e);
    }
  }
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= m; ++i) {
    read(e[i].a), read(e[i].b), read(e[i].e);
    e[i].id = i;
  }
  kruskal();
  dfs1(1);
  dfs2(1, 1);
  seg ::build(1, 1, n);
  for (int i = 1; i <= m; ++i) {
    if (anc[e[i].a] == e[i].b || anc[e[i].b] == e[i].a) continue;
    update(e[i].a, e[i].b, e[i].e);
  }
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; ++i) {
    if (anc[e[i].a] == e[i].b || anc[e[i].b] == e[i].a) {
      printf("%d\n",
             seg ::Qmin(1, 1, n,
                        anc[e[i].a] == e[i].b ? dfn[e[i].a] : dfn[e[i].b]));
    } else {
      printf("%d\n", query(e[i].a, e[i].b));
    }
  }
  return 0;
}
