#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  long long data;
  vector<node*> edges;
};
signed main() {
  long long n;
  cin >> n;
  vector<node> vertices;
  for (long long i = 0; i < n; i++) {
    node p;
    p.data = i;
    vertices.push_back(p);
  }
  vector<pair<long long, long long> > v1;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    vertices[a - 1].edges.push_back(&vertices[b - 1]);
    vertices[b - 1].edges.push_back(&vertices[a - 1]);
    v1.push_back({a - 1, b - 1});
  }
  vector<long long> ans(n, -1);
  long long count = 0;
  for (long long i = 0; i < n; i++) {
    if (vertices[i].edges.size() == 1) {
      ans[i] = count;
      count++;
    }
  }
  vector<long long> fans(n - 1, -1);
  for (long long i = 0; i < n - 1; i++) {
    if (ans[v1[i].first] != -1) {
      fans[i] = ans[v1[i].first];
    } else if (ans[v1[i].second] != -1) {
      fans[i] = ans[v1[i].second];
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (fans[i] == -1) {
      fans[i] = count;
      count++;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    cout << fans[i] << endl;
  }
  return 0;
}
