#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n + 1);
  vector<int> ans(n - 1, -1);
  for (int i = 0; i < n - 1; ++i) {
    int x1, x2;
    cin >> x1 >> x2;
    g[x1].push_back(i);
    g[x2].push_back(i);
  }
  int i = 0;
  while (i <= n && g[i].size() < 3) ++i;
  if (i <= n)
    for (int j = 0; j < 3; ++j) ans[g[i][j]] = j;
  int count = n - 1;
  for (auto& c : ans)
    if (c == -1) c = --count;
  for (auto c : ans) cout << c << endl;
  return 0;
}
