#include <bits/stdc++.h>
using namespace std;
long long n, m, in[100100], t, flag[100100], last;
struct node {
  int u, v, d;
} a[100100];
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &a[i].u, &a[i].v);
    in[a[i].u]++;
    in[a[i].v]++;
    a[i].d = -1;
  }
  for (int i = 1; i <= n - 1; i++) {
    if (in[a[i].u] > in[a[i].v]) swap(a[i].u, a[i].v);
    if (in[a[i].u] == 1) {
      if (flag[0] == 0)
        a[i].d = 0, flag[0] = 1;
      else if (flag[1] == 0)
        a[i].d = 1, flag[1] = 1;
      else if (flag[2] == 0)
        a[i].d = 2, flag[2] = 1;
      else
        break;
    }
  }
  last = 0;
  for (int i = 1; i <= n - 1; i++) {
    while (flag[last] == 1) last++;
    if (a[i].d == -1) a[i].d = last, flag[last] = 1;
  }
  for (int i = 1; i <= n - 1; i++) printf("%d\n", a[i].d);
  return 0;
}
