#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mp;
int col[100005] = {0}, k = 0, ct = 0;
vector<int> ve[100005], v;
void dfs(int a) {
  col[a] = 1;
  if (ve[a].size() == 1) {
    mp[{a, ve[a][0]}] = k;
    ++k;
    if (col[ve[a][0]] == 0) {
      dfs(ve[a][0]);
    }
  } else {
    for (int i = 0; i < ve[a].size(); i++) {
      if (ve[ve[a][i]].size() == 1) {
        mp[{a, ve[a][i]}] = k;
        ++k;
        col[ve[a][i]] = 1;
      } else {
        if (col[ve[a][i]] == 0) {
          mp[{a, ve[a][i]}] = ct;
          ++ct;
          dfs(ve[a][i]);
        }
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) v.push_back(i);
  int ar[n], ar1[n];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    ar[i] = a;
    ar1[i] = b;
    ve[a].push_back(b);
    ve[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (ve[i].size() == 1) ct++;
  }
  dfs(1);
  for (int i = 0; i < n - 1; i++) {
    cout << mp[{ar[i], ar1[i]}] << endl;
  }
  return 0;
}
