#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> adj[n + 1];
  int i, j;
  for (i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(i);
    adj[v].push_back(i);
  }
  int out[n + 1];
  memset(out, -1, sizeof(out));
  int q = 0;
  for (i = 1; i <= n; i++) {
    int count = 0;
    if (adj[i].size() > 2) {
      for (j = 0; j < adj[i].size(); j++) {
        out[adj[i][j]] = q;
        q += 1;
      }
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < adj[i].size(); j++) {
      if (out[adj[i][j]] == -1) {
        out[adj[i][j]] = q;
        q += 1;
      }
    }
  }
  for (i = 1; i < n; i++) cout << out[i] << endl;
}
