#include <bits/stdc++.h>
using namespace std;
vector<int> g[100001];
map<int, vector<pair<int, int>>> mp;
map<pair<int, int>, int> ans;
int vis[100001] = {0};
int dfs(int u) {
  vis[u] = 1;
  int d = 0;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!vis[v]) {
      d = 1 + dfs(v);
      mp[d].push_back({u, v});
    }
  }
  return d;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    ans[{u, v}] = -1;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  int k = 0;
  for (auto i : mp) {
    int f = i.first;
    for (int j = 0; j < mp[f].size(); j++) {
      int x = mp[f][j].first;
      int y = mp[f][j].second;
      k++;
      if (k == n - 1) {
        k = 0;
      }
      ans[{x, y}] = k;
    }
  }
  for (auto i : ans) {
    cout << i.second << endl;
  }
  return 0;
}
