#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x, u, v, take, ok = 0, save;
  vector<pair<long long int, long long int>> vt;
  cin >> x;
  vector<long long int> vec[x + 5];
  for (long long int i = 0; i < x - 1; i++) {
    cin >> u >> v;
    vec[u].push_back(v);
    vec[v].push_back(u);
    vt.push_back(make_pair(u, v));
  }
  for (long long int i = 0; i < x - 1; i++) {
    if (vec[vt[i].first].size() == 3) {
      take = vt[i].first;
      ok = 1;
    }
    if (vec[vt[i].second].size() == 3) {
      take = vt[i].second;
      ok = 1;
    }
  }
  if (ok) {
    long long int r = 0, l = 3;
    for (long long int i = 0; i < x - 1; i++) {
      if (vt[i].first == take or vt[i].second == take) {
        cout << r << endl;
        r++;
      } else {
        cout << l << endl;
        l++;
      }
    }
  } else {
    long long int s = 0;
    for (long long int i = 0; i < x - 1; i++) {
      cout << s << endl;
      s++;
    }
  }
}
