#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int n, u, v, t, a[maxn];
vector<int> ve[maxn];
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    ve[u].push_back(i);
    ve[v].push_back(i);
    a[i] = -1;
  }
  for (int i = 1; i < n; i++) {
    if (ve[i].size() > 2) {
      for (int j = 0; j < ve[i].size(); j++) a[i] = ve[i][j];
      break;
    }
  }
  for (int i = 1; i < n; i++) {
    if (a[i] == -1) a[i] = t++;
    cout << a[i] << endl;
  }
  return 0;
}
