#include <bits/stdc++.h>
int comp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int main() {
  int t;
  scanf("%d", &t);
  int i;
  int m = 0;
  int n = t - 2;
  int num[t + 1];
  int answer[t + 1];
  int before[t + 1];
  int after[t + 1];
  int j;
  for (j = 1; j <= t; j++) {
    num[j] = 0;
    answer[j] = -1;
    before[j] = -1;
    after[j] = -1;
  }
  int judge = 0;
  int p = 0;
  int q = -1, w = -1, e = -1;
  for (i = 1; i <= t - 1; i++) {
    int tem1, tem2;
    scanf("%d %d", &tem1, &tem2);
    answer[i] = tem2;
    num[tem1]++;
    if (num[tem1] > 1 && p == 0 && before[tem1] != -1) {
      q = i;
      int y = 0;
      for (y = 0; y < i; y++) {
        if (answer[y] == after[tem1]) {
          w = y;
          break;
        }
      }
      for (y = 0; y < i; y++) {
        if (answer[y] == tem1) {
          e = y;
          break;
        }
      }
      p = 1;
    }
    before[tem2] = tem1;
    after[tem1] = tem2;
  }
  int all = t - 2;
  if (q != -1) {
    for (j = 1; j <= t - 1; j++) {
      if (j == q) {
        printf("%d\n", 0);
      } else if (j == w) {
        printf("%d\n", 1);
      } else if (j == e) {
        printf("%d\n", 2);
      } else {
        printf("%d\n", all);
        all--;
      }
    }
  } else {
    int sum = 0;
    all = t - 2;
    for (j = 1; j <= t - 1; j++) {
      if (j % 2 == 1) {
        printf("%d\n", sum);
        sum++;
      } else {
        printf("%d\n", all);
        all--;
      }
    }
  }
}
