#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<pair<long long, long long> > v;
    pair<long long, long long> p;
    map<long long, long long> m;
    for (long long i = 0; i < n - 1; i++) {
      cin >> p.first >> p.second;
      v.push_back(p);
      m[p.first]++;
      m[p.second]++;
    }
    long long x = n - 2, y = 0;
    for (long long i = 0; i < n - 1; i++) {
      if (m[v[i].first] == 1 || m[v[i].second] == 1)
        cout << y++ << '\n';
      else
        cout << x-- << '\n';
    }
  }
  return 0;
}
