#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], dis = false;
int ans[N];
void dfs(int v) {
  vis[v] = true;
  for (auto i : g[v]) {
    if (!vis[i]) {
      dfs(i);
    }
    degree[i]++;
    if (degree[i] >= 3) dis = true;
  }
}
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);
  if (!dis) {
    int s = 0;
    for (int i = 0; i < n - 1; ++i) {
      cout << s << "\n";
      ++s;
    }
    return 0;
  }
  int s = 0;
  for (int i = 0; i < n; ++i) {
    if (degree[i] >= 3) {
      ans[i] = s;
      s++;
      for (int j = 0; j < g[i].size(); ++j) {
        ans[g[i][j]] = s;
        s++;
      }
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    if (ans[i] == -1) {
      ans[i] = s;
      s++;
    }
    cout << ans[i] << "\n";
  }
  return 0;
}
