#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, x[100010], y[100010], d[100010];
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x[i] >> y[i];
    d[x[i]]++;
    d[y[i]]++;
  }
  int count = 0;
  for (i = 1; i <= n; i++) {
    if (d[i] == 1) {
      count++;
    }
  }
  int nowx = 0, nowy = count;
  for (i = 1; i < n; i++) {
    if (d[x[i]] == 1 || d[y[i]] == 1) {
      cout << nowx++ << endl;
    } else {
      cout << nowy++ << endl;
    }
  }
  return 0;
}
