#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int edgeCounter[N];
int positionReference[N];
int ans[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(ans, -1, sizeof ans);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int bg, en;
    cin >> bg >> en;
    edgeCounter[bg]++;
    edgeCounter[en]++;
    positionReference[bg] = i;
    positionReference[en] = i;
  }
  int id = 0;
  for (int i = 1; i <= n; i++) {
    if (edgeCounter[i] == 1) {
      ans[positionReference[i]] = id;
      id++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1) {
      ans[i] = id;
      id++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << '\n';
  }
}
