#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
vector<int> graph[MAX];
int n;
map<int, vector<pair<int, int>>> mp2;
bool vis[MAX + 5];
void dfs(int s, int lev) {
  vis[s] = true;
  for (auto &x : graph[s]) {
    if (vis[x] == false) {
      mp2[lev].push_back({s, x});
      dfs(x, lev + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  map<pair<int, int>, int> mp;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
    mp[{u, v}] = i;
  }
  int ans[n + 5];
  dfs(1, 1);
  int k = 1;
  int i = 0;
  int j = 0;
  while (i < n - 1) {
    for (auto &x : mp2) {
      if (k == n - 1) k = 0;
      auto v = x.second;
      if (v.size() > j) {
        ans[mp[v[j]]] = k++;
        i++;
      }
      if (i == n - 1) break;
    }
    j++;
  }
  for (int i = 0; i < n - 1; i++) cout << ans[i] << endl;
  return 0;
}
