#include <bits/stdc++.h>
using namespace std;
typedef struct info {
  int u;
  int v;
} INFO;
vector<vector<int>> g;
vector<INFO> in;
map<pair<int, int>, int> mp;
vector<bool> visited;
void bfs(int u, int maxx) {
  queue<int> q;
  q.push(u);
  visited[u] = true;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto it : g[x]) {
      if (visited[it]) continue;
      mp[{min(x, it), max(x, it)}] = maxx;
      --maxx;
      visited[it] = true;
      q.push(it);
    }
  }
}
int main() {
  int n, x, y;
  cin >> n;
  g.resize(n + 5);
  in.resize(n + 5);
  visited.resize(n + 5);
  fill(visited.begin(), visited.end(), false);
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    if (x > y) swap(x, y);
    in[i].u = x;
    in[i].v = y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  bfs(1, n - 2);
  for (int i = 0; i < n - 1; i++) cout << mp[{in[i].u, in[i].v}] << "\n";
  return 0;
}
