#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
vector<int> v[N];
vector<pair<int, int> > ed;
int ans[N], cnt = 0;
int main() {
  std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, x, y;
  cin >> n;
  for (int i = int(0); i <= int(n); i++) ans[i] = -1;
  for (int i = int(1); i <= int(n - 1); i++) {
    cin >> x >> y;
    ed.push_back({x, y});
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int deg = 0, idx = 0;
  for (int i = int(1); i <= int(n); i++) {
    if (v[i].size() > deg) {
      deg = v[i].size();
      idx = i;
    }
  }
  if (deg >= 3) {
    for (int i = int(0); i <= int(n - 2); i++) {
      if (ed[i].first == idx || ed[i].second == idx) {
        ans[i] = cnt;
        cnt++;
      }
      if (cnt >= 3) break;
    }
  }
  for (int i = int(0); i <= int(n - 2); i++) {
    if (ans[i] == -1) {
      ans[i] = cnt;
      cnt++;
    }
  }
  for (int i = int(0); i <= int(n - 2); i++) cout << ans[i] << "\n";
}
