#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vpp = vector<pair<ll, ll> >;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, a, u, v;
  cin >> n;
  vector<int> t[n + 1];
  int ans[n][2], mx = -1, pos = n - 2, b = 0;
  for (int i = 0; i < n - 1; i++) {
    cin >> ans[i][0] >> ans[i][1];
    t[ans[i][0]].push_back(ans[i][1]);
    t[ans[i][1]].push_back(ans[i][0]);
    if (t[ans[i][0]].size() >= 3) mx = ans[i][0];
    if (t[ans[i][1]].size() >= 3) mx = ans[i][1];
  }
  for (int i = 0; i < n; i++) {
    if (ans[i][0] == mx || ans[i][1] == mx)
      cout << (b++) << "\n";
    else
      cout << (pos--) << "\n";
  }
  return 0;
}
