#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int a[maxn];
int mark[maxn];
int par[maxn];
pair<int, int> e[maxn];
vector<pair<int, int> > adj[maxn];
int bfs(int root) {
  memset(mark, 0, sizeof mark);
  queue<int> q;
  q.push(root);
  mark[root] = 1;
  int vv = root;
  while (q.size()) {
    int v = q.front();
    for (int i = 0; i < adj[v].size(); i++) {
      int u = adj[v][i].first;
      if (!mark[u]) {
        mark[u] = 1;
        q.push(u);
      }
    }
    vv = v;
    q.pop();
  }
  return vv;
}
void dfs(int v) {
  mark[v] = 2;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    if (mark[u] != 2) {
      par[u] = v;
      dfs(u);
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    e[i].first = u;
    e[i].second = v;
    adj[u].push_back({v, i});
    adj[v].push_back({u, i});
  }
  int di = bfs(1);
  int ck = bfs(di);
  memset(mark, 0, sizeof mark);
  par[di] = di;
  dfs(di);
  int p = ck;
  while (p != di) {
    mark[p] = 3;
    p = par[p];
  }
  if (n == 2) {
    cout << 0;
    return 0;
  }
  if (n == 3) {
    cout << "0\n1";
    return 0;
  }
  p = 0;
  for (int i = 1; i <= n; i++) {
    if (mark[i] != 3) {
      p = i;
      break;
    }
  }
  int ted = 3;
  bool k = 0, kk = 0, kkk = 0;
  for (int i = 1; i < n; i++) {
    if ((e[i].first == di or e[i].second == di) and k == 0) {
      cout << 1;
      k = 1;
    } else if ((e[i].first == ck or e[i].second == ck) and kk == 0) {
      cout << 0;
      kk = 1;
    } else if ((e[i].first == p or e[i].second == p) and kkk == 0) {
      cout << 2;
      kkk = 1;
    } else {
      cout << ted++;
    }
    cout << '\n';
  }
}
