#include <bits/stdc++.h>
using namespace std;
vector<int> ve[100005];
int ans[100005];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    ve[u].push_back(i);
    ve[v].push_back(i);
    ans[i] = -1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (ve[i].size() > 2) {
      for (int j = 0; j <= ve[i].size() - 1; j++) {
        int id = ve[i][j];
        if (ans[id] == -1) {
          ans[id] = cnt++;
        }
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] == -1) {
      ans[i] = cnt++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
