#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int M = 50100;
const int mod = 1e9;
int u[N], v[N], sum[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++)
    scanf("%d%d", &u[i], &v[i]), sum[u[i]]++, sum[v[i]]++;
  int l = 0, r = n - 2;
  for (int i = 1; i < n; i++) {
    if (sum[u[i]] == 1 || sum[v[i]] == 1)
      printf("%d\n", l++);
    else
      printf("%d\n", r--);
  }
  return 0;
}
