#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];
bool cmp(node a, node b) {
  int ma = max(conn[a.u], conn[a.v]);
  int mb = max(conn[b.u], conn[b.v]);
  return ma < mb;
}
bool cmp2(node a, node b) { return a.id < b.id; }
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];
  }
  sort(a + 1, a + n, cmp);
  for (int i = 1; i <= n - 1; ++i) a[i].val = i - 1;
  sort(a + 1, a + n, cmp2);
  for (int i = 1; i <= n - 1; ++i) printf("%d\n", a[i].val);
  return 0;
}
