#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
vector<pair<int, int> > each[100000 + 20];
int res[100000 + 20], used[100000 + 20];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int u, v;
    cin >> u >> v;
    each[u].push_back(make_pair(v, i));
    each[v].push_back(make_pair(u, i));
  }
  memset(res, -63, sizeof(res));
  int ok = 1;
  for (int i = 1; i <= n; ++i) {
    if (each[i].size() > 2) {
      int z = 0;
      used[0] = used[1] = used[2] = 1;
      for (auto it : each[i]) {
        res[it.second] = z++;
        if (z == 3) break;
      }
      break;
    }
  }
  int z = 3;
  if (!used[0]) z = 0;
  for (int i = 2; i <= n; ++i) {
    if (res[i] < 0) {
      cout << z++ << endl;
    } else {
      cout << res[i] << endl;
    }
  }
  return 0;
}
