#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int maxn = 3e5 + 10;
int n, u[maxn], v[maxn], ind[maxn], ans[maxn];
vector<int> adj[maxn];
int main(void) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n - 1; ++i) cin >> u[i] >> v[i];
  if (n == 2) {
    cout << 0 << '\n' << 1;
    return 0;
  }
  if (u[1] != u[2] && u[1] != v[2] && v[1] != u[2] && v[1] != v[2]) {
    for (int i = 0; i < n - 1; ++i) cout << i << '\n';
    return 0;
  }
  int t = -1;
  if (u[1] == u[2] || u[1] == v[2]) t = u[1];
  if (v[1] == u[2] || v[1] == v[2]) t = v[1];
  int idx = -1;
  for (int i = 3; i <= n - 1; ++i) {
    if (u[i] != t && v[i] != t) {
      idx = i;
      break;
    }
  }
  if (idx == -1) {
    for (int i = 0; i < n - 1; ++i) cout << i << '\n';
    return 0;
  }
  memset(ans, -1, sizeof(ans));
  for (int i = 1; i <= n - 1; ++i)
    if (idx != i) {
      if (u[i] != u[idx] && u[i] != v[idx] && v[i] != u[idx] &&
          v[i] != v[idx]) {
        ans[i] = 0;
        ans[idx] = 1;
        break;
      }
    }
  int cnt = 2;
  for (int i = 1; i <= n - 1; ++i) {
    if (ans[i] == -1) ans[i] = cnt++;
    cout << ans[i] << '\n';
  }
  return 0;
}
