#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, sz, j;
  cin >> n;
  vector<int> v[n];
  map<pair<int, int>, int> mp;
  vector<pair<int, int>> vp;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
    vp.push_back({a, b});
    mp[{a, b}] = -100;
  }
  sz = 0;
  for (int i = 0; i < n; i++) {
    if (v[i].size() >= 3) {
      sz = v[i].size();
      for (int j = 0; j < v[i].size(); j++) {
        if (mp.find({v[i][j], i}) != mp.end())
          mp[{v[i][j], i}] = j;
        else
          mp[{i, v[i][j]}] = j;
      }
      break;
    }
  }
  j = sz;
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    if (it->second == -100) it->second = j++;
  }
  for (int i = 0; i < vp.size(); i++) {
    pair<int, int> p;
    p = vp[i];
    cout << mp[p] << "\n";
  }
}
