#include <bits/stdc++.h>
using namespace std;
const int MN = 100010;
int a[MN], b[MN], du[MN];
int main() {
  int n, u = -1;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &a[i], &b[i]);
    du[a[i]]++, du[b[i]]++;
    if (du[a[i]] >= 3) u = a[i];
    if (du[b[i]] >= 3) u = b[i];
  }
  if (u == -1) {
    for (int i = 0; i < n - 1; i++) printf("%d\n", i);
    return 0;
  }
  int t1 = 0, t2 = 3;
  for (int i = 0; i < n - 1; i++) {
    if (t1 <= 2 && a[i] == u || b[i] == u)
      printf("%d\n", t1++);
    else
      printf("%d\n", t2++);
  }
  return 0;
}
