#include <bits/stdc++.h>
using namespace std;
long long inf = 1000000000000000007;
long long mod = 1000000007, col = 1, n;
vector<long long> adj[100005];
map<pair<long long, long long>, long long> sol;
void dfs(long long node, long long par) {
  for (auto u : adj[node]) {
    if (u != par) dfs(u, node);
  }
  if (!sol[{par, node}] or !sol[{node, par}]) {
    sol[{par, node}] = col;
    sol[{node, par}] = col;
    col++;
    col % (n - 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  bool flag = true;
  long long test_case = 1, tc;
  if (!flag) cin >> test_case;
  tc = test_case;
  while (tc--) {
    long long i, j, k, m, t, x, y, z, sum = 0, ans = 0, c = 0, flag = 0;
    long long maxi = -1e9, mini = 1e9;
    vector<long long> v;
    map<long long, long long> mp;
    string s;
    set<long long> st;
    cin >> n;
    long long mat[n][2];
    for (i = 0; i < n - 1; i++) {
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
      mat[i][0] = x;
      mat[i][1] = y;
    }
    if (n == 2) {
      cout << 0 << "\n";
    } else {
      for (i = 1; i <= n; i++) {
        if (adj[i].size() >= 2) {
          y = i;
          break;
        }
      }
      sol[{y, adj[y][1]}] = mini;
      sol[{adj[y][1], y}] = mini;
      dfs(y, 0);
      for (i = 0; i < n - 1; i++) {
        if (sol[{mat[i][0], mat[i][1]}] == mini or
            sol[{mat[i][1], mat[i][0]}] == mini)
          cout << 0 << "\n";
        else
          cout << sol[{mat[i][0], mat[i][1]}] << "\n";
      }
    }
  }
  return 0;
}
