#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c = getchar();
  long long x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 5;
struct node {
  int u, v;
  int val;
  int id;
} a[maxn];
int n, conn[maxn];
int main() {
  n = read();
  for (int i = 1; i <= n - 1; ++i) {
    a[i].id = i;
    a[i].u = read();
    a[i].v = read();
    ++conn[a[i].u];
    ++conn[a[i].v];
  }
  int id = 1;
  for (int i = 2; i <= n; ++i)
    if (conn[i] > conn[id]) id = i;
  if (conn[id] < 3) {
    int up = n - 1, down = 0;
    for (int i = 1; i <= n - 1; ++i) {
      if (min(conn[a[i].u], conn[a[i].v]) == 1)
        printf("%d\n", down++);
      else
        printf("%d\n", up--);
    }
  } else {
    int up = n - 1, down = 2;
    for (int i = 1; i <= n - 1; ++i) {
      if (down >= 0 && (a[i].u == id || a[i].v == id))
        printf("%d\n", down--);
      else
        printf("%d\n", up--);
    }
  }
  return 0;
}
