#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int x[maxn], n;
int a[maxn], b[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    x[a[i]]++;
    x[b[i]]++;
  }
  int t1 = 0, t2 = n - 2;
  for (int i = 1; i < n; i++) {
    if (x[a[i]] == 1 || x[b[i]] == 1)
      printf("%d\n", t1++);
    else
      printf("%d\n", t2--);
  }
  return 0;
}
