#include <bits/stdc++.h>
int main() {
  int n, i, u, v, leaves, idx_nl, idx_l;
  int label[100000];
  std::pair<int, int> edges[100000];
  std::set<int> ps;
  std::cin >> n;
  for (i = 0; i < n - 1; i++) {
    std::cin >> u >> v;
    edges[i] = std::make_pair(u, v);
    ps.insert(u);
  }
  if (n <= 3)
    for (i = 0; i < n - 1; i++) label[i] = i;
  else
    leaves = 0;
  idx_nl = n - 2;
  idx_l = 0;
  i = 0;
  while (leaves < 3)
    if (ps.find(edges[i].second) == ps.end()) {
      label[i++] = idx_l++;
      leaves++;
    } else
      label[i++] = idx_nl--;
  while (i < n - 1) label[i++] = idx_nl--;
  for (i = 0; i < n - 1; i++) std::cout << label[i] << "\n";
  return 0;
}
