#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
int n, pnt = 0, ans[N], cnt;
vector<pair<int, int> > G[N];
bool f = 0;
void DFS(int v, int p, int ind) {
  if (p != 0) {
    if (pnt == 2 && !f) pnt++, f = 1;
    ans[ind] = pnt++;
    if (pnt == n - 1) pnt = 2;
  }
  for (auto u : G[v]) {
    if (u.first == p) continue;
    DFS(u.first, v, u.second);
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int v, u;
    cin >> v >> u;
    G[v].push_back({u, i});
    G[u].push_back({v, i});
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, int(G[i].size()));
  }
  if (mx <= 2) {
    for (int i = 0; i < n - 1; i++) {
      cout << i << '\n';
    }
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (G[i].size() == 1) {
      DFS(i, 0, 0);
      break;
    }
  }
  for (int i = 1; i <= n - 1; i++) cout << ans[i] << '\n';
  return 0;
}
