#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int> > g(n);
  vector<pair<int, int> > y(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    y[i] = {a - 1, b - 1};
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  int j = 0;
  vector<int> ans(n - 1, -1);
  for (int i = 0; i < n - 1; i++) {
    if (g[y[i].second].size() == 1 || g[y[i].first].size() == 1) {
      ans[i] = j;
      j++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1) {
      ans[i] = j;
      j++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << '\n';
  }
}
