#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int maxn = 3e5 + 10;
int n, u[maxn], v[maxn], ind[maxn], ans[maxn];
vector<int> adj[maxn];
int main(void) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n - 1; ++i) {
    cin >> u[i] >> v[i];
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
    ++ind[u[i]];
    ++ind[v[i]];
  }
  int idx = 1;
  for (int i = 2; i <= n - 1; ++i) {
    if (ind[u[idx]] + ind[v[idx]] > ind[u[i]] + ind[v[i]]) idx = i;
  }
  memset(ans, -1, sizeof(ans));
  ans[idx] = 0;
  int x = min(u[idx], v[idx]), y = max(u[idx], v[idx]);
  bool chk = false;
  for (int i = 1; i <= n - 1; ++i)
    if (i != idx) {
      if (u[i] != x && u[i] != y && v[i] != x && v[i] != y) {
        ans[i] = 1;
        chk = true;
        break;
      }
    }
  int cnt = 2;
  if (!chk) cnt = 1;
  for (int i = 1; i <= n - 1; ++i)
    if (ans[i] == -1) {
      ans[i] = cnt++;
    }
  for (int i = 1; i <= n - 1; ++i) cout << ans[i] << '\n';
  return 0;
}
