#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n - 1][2];
  map<pair<int, int>, int> m;
  map<pair<int, int>, int> m2;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i][0] >> a[i][1];
    m[{a[i][0], a[i][1]}] = 1;
  }
  int c = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    pair<int, int> p = it->first;
    m2[p] = c;
    c++;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << m2[{a[i][0], a[i][1]}] << endl;
  }
}
