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