#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int n;
int d[maxn];
pair<int, int> e[maxn], p[maxn];
vector<pair<int, int> > graph[maxn];
int ans[maxn];
int dfs(int c) {
  int ret = c;
  for (pair<int, int> i : graph[c]) {
    if (i.first == p[c].first) continue;
    d[i.first] = d[c] + 1;
    p[i.first] = {c, i.second};
    int nc = dfs(i.first);
    if (d[nc] > d[ret]) ret = nc;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> e[i].first >> e[i].second;
    e[i].first--, e[i].second--;
    graph[e[i].first].push_back({e[i].second, i});
    graph[e[i].second].push_back({e[i].first, i});
  }
  p[0] = {-1, -1};
  int first = dfs(0);
  p[first] = {-1, -1};
  int g = dfs(first);
  memset(ans, -1, sizeof(ans));
  int i;
  for (i = 0; g != first; g = p[g].first, i += 1 + 2 * !i) {
    ans[p[g].second] = (p[g].first == first ? 1 : i);
  }
  i--;
  for (int j = 0, k = 2; j < n - 1; j++) {
    cout << (ans[j] == -1 ? k == 3 ? i++ : k++ : ans[j]) << '\n';
  }
  return 0;
}
