#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(cin.tie(NULL));
  cout.tie(NULL);
  long long int tc = 1;
  long long int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    unordered_map<long long int, long long int> cn;
    vector<pair<long long int, long long int> > edge;
    for (long long int i = 0; i < n - 1; i++) {
      long long int x, y;
      cin >> x >> y;
      edge.push_back(make_pair(x, y));
      cn[x]++;
      cn[y]++;
    }
    vector<pair<long long int, long long int> > tak;
    for (long long int i = 0; i < edge.size(); i++) {
      long long int x = edge[i].first;
      long long int y = edge[i].second;
      tak.push_back(make_pair(cn[x] + cn[y], i));
    }
    sort(tak.rbegin(), tak.rend());
    long long int ans[n];
    long long int val = 0;
    for (long long int i = 0; i < tak.size(); i++) {
      ans[tak[i].second] = val++;
    }
    for (long long int i = 0; i < n - 1; i++) {
      cout << ans[i] << endl;
    }
  }
}
