#include <bits/stdc++.h>
using namespace std;
int n, ans[100005];
vector<pair<int, int> > g[100005];
int main() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    ans[i] = -1;
    int x, y;
    cin >> x >> y;
    g[x].push_back({y, i});
    g[y].push_back({x, i});
  }
  for (long long i = 1; i <= n; i++) {
    if (g[i].size() > 2) {
      int x = g[i][0].second;
      int y = g[i][1].second;
      int z = g[i][2].second;
      ans[x] = 0;
      ans[y] = 1;
      ans[z] = 2;
      int idx = 3;
      for (long long i = 1; i < n; i++) {
        if (ans[i] == -1) {
          ans[i] = idx;
          idx++;
        }
      }
      for (long long i = 1; i < n; i++) cout << ans[i] << endl;
      return 0;
    }
  }
  for (long long i = 1; i < n; i++) cout << i - 1 << endl;
}
