#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int u[n], v[n];
  vector<int> adj[n + 1];
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    u[i] = x;
    v[i] = y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int ma = 0;
  for (int i = 1; i <= n; i++) {
    int y = adj[i].size();
    ma = max(ma, y);
  }
  if (ma <= 2) {
    for (int i = 1; i < n; i++) cout << i - 1 << endl;
  } else {
    int h;
    for (int i = 1; i <= n; i++) {
      if (adj[i].size() > 2) {
        h = i;
        break;
      }
    }
    int g = n - 2;
    int d = 0;
    for (int i = 1; i <= n - 1; i++) {
      if (u[i] == h || v[i] == h) {
        cout << d << endl;
        d++;
      } else {
        cout << g << endl;
        g--;
      }
    }
  }
  return 0;
}
