#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, v1, v2, v3, v4, v5, v6;
set<long long int> st, st1, st2, st3;
map<pair<long long int, long long int>, long long int> Mp;
vector<pair<long long int, long long int> > vec;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t, n, m, a, b, c = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    if (Mp[{a, b}] == 0) {
      Mp[{a, b}] = c;
      c++;
    }
  }
  for (auto x : Mp) {
    cout << x.second << endl;
  }
  return 0;
}
