#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
const int MAX = 1e5;
const int mxn = 1e5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1000010;
vector<int> g[N];
int degree[N];
bool vis[N];
int ans[N];
void dfs(int v) {
  vis[v] = true;
  for (auto i : g[v]) {
    if (!vis[i]) {
      dfs(i);
    }
    degree[i]++;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    vis[i] = false;
    degree[i] = 0;
    ans[i] = -1;
  }
  dfs(0);
  int mx = -1, s = 0;
  for (int i = 0; i < n; ++i) mx = max(mx, degree[i]);
  for (auto i : g[mx]) ans[i] = s++;
  for (int i = 0; i < n - 1; ++i) {
    if (ans[i] == -1) ans[i] = s++;
    cout << ans[i] << "\n";
  }
  return 0;
}
