#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n - 1], b[n - 1], hsh[n];
  memset(hsh, 0, sizeof(hsh));
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    hsh[a[i] - 1]++;
    hsh[b[i] - 1]++;
  }
  int label[n - 1];
  int l = 0;
  for (int i = 0; i < n - 1; i++) {
    label[i] = -1;
  }
  for (int i = 0; i < n - 1; i++) {
    if (hsh[a[i] - 1] == 1 || hsh[b[i] - 1] == 1) {
      label[i] = l;
      l++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (label[i] == -1) {
      label[i] = l;
      l++;
    }
    cout << label[i] << '\n';
  }
  return 0;
}
