#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr[n + 2];
  int a, b;
  pair<int, pair<int, int>> r[n + 2];
  for (long long i = 2; i <= n; i++) {
    scanf("%d%d", &a, &b);
    arr[a].push_back(b);
    arr[b].push_back(a);
    r[i - 1] = make_pair(-1, make_pair(a, b));
  }
  int j = 0;
  for (long long i = 2; i <= n; i++) {
    if ((arr[r[i - 1].second.first].size()) == 1 or
        (arr[r[i].second.second].size()) == 1)
      r[i - 1].first = j++;
  }
  for (long long i = 2; i <= n; i++) {
    if (r[i - 1].first == -1) r[i - 1].first = j++;
  }
  for (long long i = 2; i <= n; i++) {
    printf("%d\n", r[i - 1].first);
  }
  return 0;
}
