#include <bits/stdc++.h>
using namespace std;
class Solution {
 private:
  int n;
  vector<pair<int, int> > edges;
  vector<int> deg;

 public:
  Solution() {
    scanf("%d", &n);
    deg = vector<int>(n, 0);
    int u, v;
    for (int i = 1; i < n; i++) {
      scanf("%d %d", &u, &v);
      u--;
      v--;
      edges.push_back({u, v});
      deg[u]++;
      deg[v]++;
    }
  }
  void solve() {
    int l = 0, r = n - 2, u, v;
    for (int i = 0; i < n - 1; i++) {
      u = edges[i].first;
      v = edges[i].second;
      if (deg[u] == 1 || deg[v] == 1)
        printf("%d\n", l++);
      else
        printf("%d\n", r--);
    }
  }
};
int main() {
  Solution *sol = new Solution();
  sol->solve();
  return 0;
}
