#include <bits/stdc++.h>
using namespace std;
const long long int MAX_N = 1e5 + 7, delta = 10343;
long long int cnt[MAX_N];
map<pair<long long int, long long int>, long long int> mp;
vector<long long int> adj[MAX_N];
int32_t main() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    cnt[a]++, cnt[b]++;
    adj[a].push_back(b), adj[b].push_back(a);
    mp[{a, b}] = mp[{b, a}] = i;
  }
  long long int ans[3] = {}, idx = 0;
  for (long long int i = 1; i <= n; i++) {
    if (cnt[i] == 1) {
      ans[idx++] = i;
      if (idx > 2) break;
    }
  }
  long long int sz = 2;
  long long int j[MAX_N] = {};
  j[mp[{ans[0], adj[ans[0]][0]}]] = 1;
  j[mp[{ans[1], adj[ans[1]][0]}]] = 2;
  if (idx >= 3) j[mp[{ans[2], adj[ans[2]][0]}]] = 3, sz++;
  for (long long int i = 1; i < n; i++) {
    if (j[i])
      cout << j[i] - 1 << endl;
    else
      cout << sz++ << endl;
  }
  return 0;
}
