#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int N = 100010;
int ans[N];
int en, head[N];
struct Edge {
  int to, nxt, val;
} e[N << 1];
inline void add(int x, int y, int z) {
  e[++en].to = y;
  e[en].val = z;
  e[en].nxt = head[x];
  head[x] = en;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1, x, y; i < n; ++i) {
    ans[i] = -1;
    scanf("%d %d", &x, &y);
    add(x, y, i), add(y, x, i);
  }
  int cnt = -1;
  for (int i = 1; i <= n; ++i) {
    int num = 0;
    for (int j = head[i]; j; j = e[j].nxt) {
      ++num;
    }
    if (num >= 3) {
      for (int j = head[i]; j; j = e[j].nxt) {
        ans[e[j].val] = ++cnt;
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    if (ans[i] == -1) {
      ans[i] = ++cnt;
    }
    printf("%d\n", ans[i]);
  }
  return 0;
}
