#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n;
int deg[N];
int ans[N];
int num[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) ans[i] = -1;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    deg[v]++;
    deg[u]++;
    num[v] = i;
    num[u] = i;
  }
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 1) {
      if (ans[num[i]] == -1) {
        ans[num[i]] = tmp++;
      }
    }
    if (tmp >= 3) break;
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] == -1) ans[i] = tmp++;
  }
  for (int i = 1; i < n; i++) printf("%d\n", ans[i]);
  return 0;
}
