#include <bits/stdc++.h>
using namespace std;
int edge[100005][2];
int deg[100005];
int main() {
  ios ::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int a = 0; a < n - 1; a++) {
    cin >> edge[a][0] >> edge[a][1];
    deg[edge[a][0]]++;
    deg[edge[a][1]]++;
  }
  int x = n - 2;
  int y = 0;
  for (int a = 0; a < n - 1; a++) {
    if (deg[edge[a][0]] > 2 || deg[edge[a][1]] > 2)
      cout << y++ << "\n";
    else
      cout << x-- << "\n";
  }
  return 0;
}
