#include <bits/stdc++.h>
using namespace std;
const long long int MAX_N = 1e5 + 7, delta = 10343;
long long int n, u1, u2, md = 0;
map<pair<long long int, long long int>, long long int> mp;
vector<long long int> adj[MAX_N];
long long int sz = 1, w;
long long int ans[MAX_N];
void dfs1(long long int v, long long int d, long long int par) {
  if (d > md) md = d, u1 = v;
  for (long long int x : adj[v])
    if (x != par) dfs1(x, d + 1, v);
}
void dfs2(long long int v, long long int d, long long int par) {
  if (d > md) md = d, u2 = v;
  for (long long int x : adj[v])
    if (x != par) dfs2(x, d + 1, v);
}
void dfs3(long long int v, long long int par) {
  for (long long int x : adj[v])
    if (x != par) {
      dfs3(x, v);
    }
  if (v == w) {
    ans[mp[{par, v}]] = sz--;
    w = par;
  }
}
int32_t main() {
  cin >> n;
  for (long long int i = 1; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    mp[{a, b}] = i;
    mp[{b, a}] = i;
  }
  dfs1(1, 0, -1);
  md = 0;
  dfs2(u1, 0, -1);
  w = u2;
  sz = n - 1;
  dfs3(u1, -1);
  for (long long int i = 1; i < n; i++) {
    if (ans[i])
      cout << ans[i] - 1 << endl;
    else {
      cout << sz << endl;
      sz--;
    }
  }
  return 0;
}
