#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, x, y, edge[100001];
  vector<long long> v[100001];
  map<pair<long long, long long>, long long> mp;
  cin >> n;
  memset(edge, -1, sizeof(edge));
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    mp[{x, y}] = i;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (i = 1; i <= n; i++)
    if (v[i].size() > 2) break;
  if (i > n) {
    for (i = 0; i < n - 1; i++) cout << i << "\n";
    return 0;
  }
  for (j = 0; j < 3; j++) {
    if (mp.find({v[i][j], i}) != mp.end()) {
      edge[mp[{v[i][j], i}]] = j;
    } else
      edge[mp[{i, v[i][j]}]] = j;
  }
  x = 3;
  for (i = 0; i < n - 1; i++) {
    if (edge[i] == -1) {
      cout << x << "\n";
      x++;
    } else
      cout << edge[i] << "\n";
  }
  return 0;
}
