#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, INF = 1e9 + 7, mod = 1e9 + 7;
const double PI = 3.141592653589793238462643383279502884197, eps = 1e-9;
map<pair<int, int>, int> mp;
vector<int> tree[N];
int cnt;
bool dfs(int u, int p, int v) {
  if (u == v) return 1;
  for (int i : tree[u])
    if (i != p && dfs(i, u, v)) {
      if (mp[{i, u}] == -1) mp[{i, u}] = mp[{u, i}] = cnt++;
      return 1;
    }
  return 0;
}
void solve(int x, int p) {
  if (mp[{x, p}] == -1) mp[{x, p}] = mp[{p, x}] = cnt++;
  for (int i : tree[x])
    if (i != p) solve(i, x);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, u, v;
  vector<pair<int, int> > vec;
  cin >> n;
  if (n == 2) return cout << 0, 0;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    tree[u].push_back(v);
    tree[v].push_back(u);
    mp[{u, v}] = mp[{v, u}] = -1;
    vec.push_back({u, v});
  }
  u = v = -1;
  for (int i = 1; i <= n; i++)
    if (tree[i].size() == 1 && i != u && i != v) {
      if (u == -1)
        u = i, v = tree[i][0], mp[{u, v}] = mp[{v, u}] = 0;
      else {
        v = i;
        mp[{i, tree[i][0]}] = mp[{tree[i][0], i}] = 1;
        break;
      }
    }
  cnt = 3;
  dfs(u, -1, v);
  v = cnt;
  solve(u, -1);
  for (pair<int, int> i : vec) {
    if (mp[i] == n - 1)
      cout << 2;
    else
      cout << mp[i];
    cout << '\n';
  }
  return 0;
}
