#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t, i, n, x, y;
  cin >> n;
  long long arr[200010] = {0};
  vector<pair<long long, long long> > v;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    arr[x]++;
    arr[y]++;
    v.push_back({x, y});
  }
  for (i = 1; i <= n; i++) {
    if (arr[i] == 1) break;
  }
  long long ans[n - 1];
  y = 0;
  for (i = 0; i < v.size(); i++) {
    if (arr[v[i].first] == 0 || arr[v[i].second] == 0) ans[i] = y++;
  }
  for (i = 0; i < v.size(); i++) {
    if (!(arr[v[i].first] == 0 || arr[v[i].second] == 0)) ans[i] = y++;
  }
  for (i = 0; i < v.size(); i++) {
    cout << ans[i] << '\n';
  }
}
