#include <bits/stdc++.h>
using namespace std;
const long long sz = (long long)1e5 + 5;
unordered_map<long long, long long> deg;
vector<long long> g[sz];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, u, v;
  cin >> n;
  if (n == 2) {
    cout << "0" << endl << "1" << endl;
  } else {
    set<long long> s;
    for (long long i = 0; i < n - 1; i++) s.insert(i);
    vector<pair<long long, long long> > edg;
    map<pair<long long, long long>, long long> col;
    for (long long i = 0; i < n - 1; i++) {
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
      edg.push_back({u, v});
      col[{u, v}] = -1;
      deg[u]++;
      deg[v]++;
    }
    long long ch = -1, ch2 = -1;
    for (long long i = 1; i <= n; i++) {
      if (deg[i] >= 3) {
        ch = i;
        break;
      }
    }
    if (ch == -1) {
      for (long long i = 1; i <= n; i++) {
        if (deg[i] == 2) {
          ch2 = i;
          break;
        }
      }
      long long cnt = 0;
      for (auto i : edg) {
        if (i.first == ch2 || i.second == ch) {
          if (cnt < 2) {
            col[i] = cnt;
            s.erase(cnt);
            cnt++;
          }
        }
      }
      for (auto i : edg) {
        if (col[i] == -1) {
          col[i] = *s.begin();
          s.erase(s.begin());
        }
      }
      for (auto i : edg) {
        cout << col[i] << endl;
      }
      return 0;
    } else {
      long long cnt = 0;
      for (auto i : edg) {
        if ((i.first == ch || i.second == ch) && cnt < 3) {
          col[i] = cnt;
          s.erase(cnt);
          cnt++;
        }
      }
      for (auto i : edg) {
        if (col[i] == -1) {
          col[i] = *s.begin();
          s.erase(s.begin());
        }
      }
      for (auto i : edg) {
        cout << col[i] << endl;
      }
    }
  }
  return 0;
}
