#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 5;
vector<int> adj[mxn];
int ans[mxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int j = 0;
  for (int i = 1; i < n; ++i) {
    if (adj[i - 1].size() > 1) {
      continue;
    }
    if (adj[i - 1].size() == 1) {
      ans[i] = j++;
    }
  }
  for (int i = 1; i < n; ++i) {
    if (adj[i - 1].size() == 1) {
      continue;
    } else {
      ans[i] = j++;
    }
  }
  for (int i = 1; i < n; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
