#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v[100005];
  vector<int> cnt(100005);
  vector<int> ans(100005, -1);
  int mx = 0, MN = 0;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(i);
    v[b].push_back(i);
    cnt[a]++;
    cnt[b]++;
    if (cnt[a] > mx) {
      mx = cnt[a];
      MN = a;
    }
    if (cnt[b] > mx) {
      mx = cnt[b];
      MN = b;
    }
  }
  int val = 0;
  for (int i = 1; i < n; i++) {
    if (ans[i] == -1) ans[i] = val++;
    cout << ans[i] << endl;
  }
  return 0;
}
