#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  v.resize(n + 1);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back({b, i}), v[b].push_back({a, i});
  }
  if (n == 2) {
    cout << "0";
  } else if (n == 3) {
    cout << "0 1";
  } else {
    vector<int> ans(n - 1, -1);
    int st = 0;
    for (int i = 1; i <= n; ++i) {
      if (v[i].size() == 1) {
        ans[v[i][0].second] = st++;
      }
    }
    for (int i = 0; i < n - 1; ++i) {
      if (ans[i] == -1) ans[i] = st++;
    }
    for (int i : ans) cout << i << '\n';
  }
  return 0;
}
