#include <bits/stdc++.h>
using namespace std;
const int maxn = 20010;
struct node {
  int s;
  int id;
};
vector<node> G[maxn];
int ans[maxn];
int main() {
  int n;
  memset(ans, -0x3f, sizeof(ans));
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    G[u].push_back(node{v, i});
    G[v].push_back(node{u, i});
  }
  int now = 0;
  for (int i = 0; i < n; i++) {
    if (G[i].size() > 2) {
      for (int j = 0; j < 3; j++) {
        ans[G[i][j].id] = now++;
        break;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] < 0) ans[i] = now++;
  }
  for (int i = 1; i < n; i++) printf("%d\n", ans[i]);
  return 0;
}
