#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;
vector<int> adj[N];
int deg[N];
int ans[N], fin[N];
pair<int, int> edge_list[N];
int n;
int num = 0;
int seen[N];
void DFS(int src) {
  for (auto v : adj[src]) {
    if (ans[v] == -1) {
      ans[v] = num++;
      DFS(v);
    }
  }
}
int main() {
  memset(ans, -1, sizeof ans);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++;
    deg[v]++;
    edge_list[i] = {u, v};
  }
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 1) ans[i] = num++;
  }
  for (int i = 0; i < n - 1; i++) {
    int u = edge_list[i].first, v = edge_list[i].second;
    if (ans[u] != -1 && !seen[ans[u]]) {
      cout << ans[u] << endl;
      seen[ans[u]] = 1;
    } else if (ans[v] != -1 && !seen[ans[v]]) {
      cout << ans[v] << endl;
      seen[ans[v]] = 1;
    } else {
      cout << num++ << endl;
    }
  }
  return 0;
}
