#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
void DEBUG(string label, T value) {
  cerr << "[" << label << " = " << value << "]\n";
}
int V;
vector<vector<int>> adj;
map<pair<int, int>, int> mark;
vector<pair<int, int>> edges;
void solve() {
  cin >> V;
  adj.assign(V, vector<int>());
  edges.resize(V - 1);
  for (int i = 0; i < V - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    if (a > b) {
      swap(a, b);
    }
    edges[i] = {a, b};
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int cnt = 0;
  pair<int, int> mx = {-1, -1};
  for (int i = 0; i < V; ++i) {
    mx = max(mx, {adj[i].size(), i});
  }
  for (auto i : adj[mx.second]) {
    int a = mx.second;
    int b = i;
    if (a > b) {
      swap(a, b);
    }
    mark[{a, b}] = cnt++;
  }
  for (int i = 0; i < V; ++i) {
    for (int j : adj[i]) {
      int a = i;
      int b = j;
      if (a > b) {
        swap(a, b);
      }
      if (mark.count({a, b}) == 0) {
        mark[{a, b}] = cnt++;
      }
    }
  }
  assert(cnt == V - 1);
  for (int i = 0; i < edges.size(); ++i) {
    int a = edges[i].first;
    int b = edges[i].second;
    assert(mark.count({a, b}) != 0);
    cout << mark[{a, b}] << endl;
  }
}
int main(int argv, char **argc) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
