#include <bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;
vector<pair<long long int, long long int>> v[N];
int main() {
  long long int n;
  cin >> n;
  long long int ans[n];
  for (int i = 0; i < n - 1; i++) ans[i] = -1;
  for (int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    v[x].push_back({y, i});
    v[y].push_back({x, i});
  }
  long long int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() >= 3) {
      for (auto j : v[i]) {
        if (ans[j.second] == -1) ans[j.second] = cnt;
        cnt++;
      }
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1) {
      ans[i] = cnt;
      cnt++;
    }
  }
  for (int i = 0; i < n - 1; i++) cout << ans[i] << '\n';
}
