#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> v[n];
  int a = -1;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    if (a != -1) continue;
    --x, --y;
    v[x].push_back(i);
    v[y].push_back(i);
    if (v[x].size() > 2) a = x;
    if (v[y].size() > 2) a = y;
  }
  if (a == -1) {
    for (int i = 0; i < n - 1; ++i) cout << i << '\n';
    return 0;
  }
  int num = 3;
  for (int i = 0; i < n - 1; ++i) {
    if (i == v[a][0])
      cout << "0\n";
    else if (i == v[a][1])
      cout << "1\n";
    else if (i == v[a][2])
      cout << "2\n";
    else
      cout << num++ << '\n';
  }
}
