#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<tuple<int, int, int> > tp(n - 1);
  int a, b;
  unordered_map<int, int> mp;
  int i;
  int p = -1;
  for (i = 0; i < n - 1; i++) {
    cin >> a >> b;
    get<0>(tp[i]) = a;
    get<1>(tp[i]) = b;
    get<2>(tp[i]) = (-1);
    mp[a]++;
    mp[b]++;
    if (mp[a] == 3 && p == (-1)) {
      p = a;
    } else if (mp[b] == 3 && p == (-1)) {
      p = b;
    }
  }
  if (p != (-1)) {
    int count = 3;
    int z = 2;
    for (i = 0; i < n - 1; i++) {
      if ((get<0>(tp[i]) == p || get<1>(tp[i]) == p) && (z + 1)) {
        get<2>(tp[i]) = z;
        z--;
        continue;
      }
      get<2>(tp[i]) = count;
      count++;
    }
  } else {
    int count = 0;
    for (i = 0; i < n - 1; i++) {
      get<2>(tp[i]) = count;
      count++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << get<2>(tp[i]) << "\n";
  }
}
