#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > edges(n - 1);
  vector<int> deg(n + 1, 0);
  int root = -1;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    edges[i] = {u, v};
    deg[u]++, deg[v]++;
    if (deg[u] > 2 && root == -1) root = u;
    if (deg[v] > 2 && root == -1) root = v;
  }
  if (root == -1)
    for (int i = 0; i < n - 1; i++) cout << i << "\n";
  else {
    unordered_set<int> w;
    int rootEdgeWeight = 0;
    for (int i = 3; i < n - 1; i++) w.insert(i);
    for (const auto &p : edges) {
      int u = p.first, v = p.second;
      if ((u == root || v == root) && rootEdgeWeight < 3) {
        cout << rootEdgeWeight++ << "\n";
      } else {
        cout << *w.begin() << "\n";
        w.erase(w.begin());
      }
    }
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
