#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > a[n + 1];
  int answer[n];
  for (int i = 0; i < n; i++) answer[i] = -1;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back({y, i});
    a[y].push_back({x, i});
  }
  bool idc = true;
  for (int i = 1; i <= n; i++) {
    if (a[i].size() > 2) {
      idc = false;
      for (int j = 0; j < 3; j++) {
        answer[a[i][j].second] = j;
      }
      break;
    }
  }
  if (idc) {
    for (int i = 0; i < n - 1; i++) cout << i << "\n";
  } else {
    int count = 3;
    for (int i = 0; i < n - 1; i++) {
      if (answer[i] == -1) {
        cout << count << "\n";
        count++;
      } else {
        cout << answer[i] << "\n";
      }
    }
  }
  return 0;
};
