#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<int, int>> v;
  map<int, int> m;
  int ver, ma = 0;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back({a, b});
    m[a]++;
    m[b]++;
  }
  for (auto a : m) {
    if (a.second > ma) {
      ma = a.second;
      ver = a.first;
    }
  }
  int c = 0;
  vector<int> ans(n - 1, -1);
  for (int i = 0; i < n - 1; i++) {
    if (v[i].first == ver || v[i].second == ver) {
      ans[i] = c;
      c++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1) {
      ans[i] = c;
      c++;
    }
    cout << ans[i] << endl;
  }
  return 0;
}
