#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double pi = acos(-1.0);
map<long long, map<long long, long long>> ans;
bool vis[200005];
map<long long, map<long long, long long>> g;
map<long long, long long> taken;
long long p;
vector<long long> v[200005];
void dfs(long long node) {
  vis[node] = true;
  for (auto& x : v[node]) {
    if (!vis[x]) {
      g[node][x] = 1;
      ans[node][x] = p;
      p++;
      dfs(x);
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt;
  tt = 1;
  while (tt--) {
    long long n;
    cin >> n;
    vector<pair<long long, long long>> k;
    for (long long i = 0; i < n - 1; i++) {
      long long p, q;
      cin >> p >> q;
      k.push_back(make_pair(p, q));
      v[p].push_back(q);
      v[q].push_back(p);
    }
    bool check = false;
    memset(vis, false, sizeof(vis));
    for (long long i = 1; i <= n; i++) {
      if (v[i].size() >= 3) {
        check = true;
        vis[i] = true;
        ans[i][v[i][0]] = 2;
        g[i][v[i][0]] = 1;
        p = 3;
        dfs(v[i][0]);
        ans[i][v[i][1]] = 1;
        g[i][v[i][1]] = 1;
        dfs(v[i][1]);
        ans[i][v[i][2]] = 0;
        g[i][v[i][2]] = 1;
        dfs(v[i][2]);
        for (auto& x : v[i]) {
          if (!vis[x]) {
            ans[i][x] = p;
            g[i][x] = 1;
            dfs(x);
          }
        }
        break;
      }
    }
    if (check) {
      for (auto& x : k) {
        long long p = x.first;
        long long q = x.second;
        if (g[p][q] == 1) {
          cout << ans[p][q] << "\n";
        } else {
          cout << ans[q][p] << '\n';
        }
      }
    } else {
      long long cnt = 0;
      for (auto& x : k) {
        cout << cnt << "\n";
        cnt++;
      }
    }
  }
  return 0;
}
