#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  vector<vector<int> > g(n + 1);
  vector<pair<int, int> > a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i].first >> a[i].second;
    g[a[i].first].push_back(a[i].second);
    g[a[i].second].push_back(a[i].first);
  }
  int vert = -1, nxt2 = 0, nxt1 = 0;
  for (int i = 1; i <= n; i++) {
    if (g[i].size() >= 3) {
      vert = i;
      nxt2 = g[i].size();
      break;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (a[i].first == vert || a[i].second == vert) {
      cout << nxt1 << "\n";
      nxt1++;
    } else {
      cout << nxt2 << "\n";
      nxt2++;
    }
  }
}
