#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1, i, j;
  while (t--) {
    int n;
    cin >> n;
    int u, w;
    vector<int> adj[n + 1];
    vector<pair<int, int>> v;
    for (i = 0; i < n - 1; i++) {
      cin >> u >> w;
      v.push_back({u, w});
      adj[u].push_back(w);
      adj[w].push_back(u);
    }
    vector<pair<int, int>> size;
    for (i = 1; i <= n; i++) size.push_back({adj[i].size(), i});
    sort(size.begin(), size.end());
    map<pair<int, int>, int> mp;
    int count = 0;
    for (i = size.size() - 1; i >= 0; i--) {
      int temp = size[i].second;
      for (j = 0; j < adj[temp].size(); j++) {
        if (mp.find({min(temp, adj[temp][j]), max(temp, adj[temp][j])}) ==
            mp.end()) {
          mp[{min(temp, adj[temp][j]), max(temp, adj[temp][j])}] = count;
          count++;
        }
      }
    }
    for (i = 0; i < v.size(); i++) {
      cout << mp[{v[i].first, v[i].second}] << "\n";
    }
  }
  return 0;
}
