#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
vector<int> v[150000];
int n;
vector<pair<int, int>> vv;
void solve() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    vv.push_back({x, y});
    v[x].push_back(y);
    v[y].push_back(x);
  }
  vector<int> v1;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() == 1) v1.push_back(i);
  }
  int a = v1[0];
  int b = v1[1];
  int k = 2;
  int c = 0;
  if (v1.size() >= 3) {
    c = v1[2];
    k = 3;
  }
  for (int i = 0; i < vv.size(); i++) {
    if (vv[i].first == a || vv[i].second == a) {
      cout << 1 << '\n';
    } else if (vv[i].first == b || vv[i].second == b) {
      cout << 0 << '\n';
    } else if (vv[i].first == c || vv[i].second == c) {
      cout << 2 << '\n';
    } else {
      cout << k++ << '\n';
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int TestCase;
  TestCase = 1;
  while (TestCase--) solve();
  return 0;
}
