#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> index(n);
  map<int, vector<int>> m;
  map<pair<int, int>, int> p;
  vector<int> ans(n - 1);
  vector<pair<int, int>> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    a[i] = {l, r};
    index[l] = 0;
    p[{l, r}] = i;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    m[a[i].first].push_back(a[i].second);
  }
  bool flag = true;
  int i = 0;
  while (flag) {
    flag = false;
    for (auto z : m) {
      if (index[z.first] < z.second.size()) {
        ans[p[{z.first, z.second[index[z.first]]}]] = i;
        i++;
        index[z.first]++;
        flag = true;
      }
    }
  }
  for (auto as : ans) {
    cout << as << "\n";
  }
}
