#include <bits/stdc++.h>
using namespace std;
vector<long long> v[100005];
long long vis[100005];
map<pair<long long, long long>, long long> m;
long long n, val;
void dfs(long long top) {
  vis[top] = 1;
  for (long long i = 0; i < v[top].size(); i++) {
    if (vis[v[top][i]] == 0) {
      m[{top, v[top][i]}] = val;
      m[{v[top][i], val}] = val;
      if (val + 2 == n - 1)
        val = 1;
      else {
        val = (val + 2) % (n - 1);
      }
      dfs(v[top][i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, i, j, k, q, x, y, l, r, z;
  cin >> n;
  vector<pair<long long, long long> > edg;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    edg.push_back({x, y});
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1);
  for (i = 0; i < n - 1; i++) {
    cout << m[{edg[i].first, edg[i].second}] << endl;
  }
}
