#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<int> v[n + 1];
  long long ans[n];
  for (int i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(i);
    v[y].push_back(i);
    ans[i] = -1;
  }
  long long cur = 0;
  long long mark = 0, mark1 = v[1].size();
  for (long long i = 1; i < n + 1; i++) {
    if (mark1 < v[i].size()) {
      mark1 = v[i].size();
      mark = i;
    }
  }
  for (auto u : v[mark]) {
    ans[u] = cur++;
  }
  for (long long i = 1; i < n; i++) {
    if (ans[i] == -1) ans[i] = cur++;
  }
  for (int i = 1; i < n; i++) cout << ans[i] << endl;
}
