#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<pair<int, int> > e;
int n, dg[N], ans[N], rn;
vector<pair<int, int> > gr[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  rn = n - 2;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    dg[x]++, dg[y]++;
    gr[x].push_back({y, i}), gr[y].push_back({x, i});
  }
  memset(ans, -1, sizeof(ans));
  for (int i = 0; i < n; i++) {
    if (dg[i] > 2) {
      for (int j = 0; j < 3; j++) {
        auto p = gr[i][j];
        ans[p.second] = j;
      }
      break;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == -1)
      cout << rn << "\n", rn--;
    else
      cout << ans[i] << "\n";
  }
  return 0;
}
