#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector<pair<int, int> > g[N];
int ans[N];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    if (g[i].size() > 2) {
      for (auto j : g[i]) {
        ans[j.second] = cnt++;
      }
      break;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    if (ans[i] == 0) ans[i] = cnt++;
    cout << ans[i] - 1 << endl;
  }
}
