#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > adj;
vector<int> color;
set<int> st;
void dfs(int s, int par) {
  for (auto it : adj[s]) {
    if (it.first == par) continue;
    if (adj[it.first].size() == 1) {
      color[it.second] = *st.begin();
      st.erase(st.begin());
    } else
      dfs(it.first, s);
  }
}
int main() {
  int n;
  cin >> n;
  adj.resize(n + 1);
  color.resize(n, -1);
  for (int i = 0; i <= n - 2; i++) {
    st.insert(i);
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back({y, i});
    adj[y].push_back({x, i});
  }
  int ele = 1;
  for (int i = 1; i <= n; i++) {
    if (adj[ele].size() >= 2) {
      ele = i;
    }
  }
  dfs(ele, 0);
  for (int i = 1; i < n; i++) {
    if (color[i] == -1) {
      color[i] = *st.begin();
      st.erase(st.begin());
    }
  }
  for (int i = 1; i < n; i++) {
    cout << color[i] << endl;
  }
}
