#include <bits/stdc++.h>
using namespace std;
int n, root = 1, x, d[100005];
pair<int, int> a[100005];
int ans[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n - 1; i++)
    cin >> a[i].first >> a[i].second, d[a[i].first]++, d[a[i].second]++;
  for (int i = 1; i <= n; i++)
    if (d[i] >= 3) root = i;
  for (int i = 1; i <= n - 1; i++) {
    if (a[i].first == root || a[i].second == root) ans[i] = ++x;
  }
  for (int i = 1; i <= n - 1; i++)
    if (ans[i] == 0) ans[i] = ++x;
  for (int i = 1; i <= n - 1; i++) cout << ans[i] - 1, cout << "\n";
}
