#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)(1e18);
const long long inf = 1e9 + 7;
long double eps = 1e-8;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long mod = inf;
vector<vector<pair<int, int>>> g;
vector<int> s;
vector<pair<int, int>> E;
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back({b, i});
    g[b].push_back({a, i});
    E.push_back({a, b});
  }
  vector<int> res(n - 1, -1);
  int it = 0;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    if (g[i].size() > 2) {
      flag = true;
      int ind = -1;
      for (int j = 0; j < g[i].size(); j++) {
        if (g[g[i][j].first].size() > 1) {
          ind = j;
          for (auto e : g[g[i][j].first]) {
            if (e.second != g[i][j].second) {
              res[e.second] = 1;
            }
          }
          break;
        }
      }
      int cnt = 0;
      for (int j = 0; j < g[i].size() && cnt < 2; j++) {
        if (j == ind) continue;
        cnt++;
        res[g[i][j].second] = it;
        it += 2;
      }
    }
  }
  if (!flag) {
    for (int i = 0; i < n - 1; i++) cout << i << endl;
    return 0;
  }
  if (it != 0) it--;
  for (int i = 0; i < n - 1; i++) {
    if (res[i] == -1) res[i] = it++;
    if (it == 2) it++;
    cout << res[i] << '\n';
  }
}
