#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200006];
int n, m;
int color[200006];
void solve() {
  cin >> n;
  int k = -1;
  int color[n];
  memset(color, -1, sizeof color);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(i);
    adj[y].push_back(i);
    if (adj[x].size() >= 3) {
      k = x;
    }
    if (adj[y].size() >= 3) {
      k = y;
    }
  }
  int g = 0;
  if (k != -1) {
    for (int i = 0; i < 3; i++) {
      color[adj[k][i]] = g++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (color[i] == -1) color[i] = g++;
    cout << color[i] << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
}
