#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int inf = 1e9;
const int mo = 998244353;
vector<int> a[N];
int ans[N];
int main() {
  int n;
  cin >> n;
  memset(ans, -1, sizeof(ans));
  for (auto i = (1); i <= (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(i);
    a[v].push_back(i);
  }
  bool flag = 0;
  for (auto i = (1); i <= (n); ++i) {
    if (a[i].size() >= 3) {
      for (auto j = (1); j <= (a[i].size()); ++j) {
        ans[a[i][j - 1]] = j - 1;
      }
      flag = 1;
      break;
    }
  }
  int now = 3;
  if (!flag) now = 0;
  for (auto i = (1); i <= (n - 1); ++i) {
    if (ans[i] == -1)
      cout << now++;
    else
      cout << ans[i];
    cout << endl;
  }
  return 0;
}
