#include <bits/stdc++.h>
using namespace std;
stringstream vin, vout;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
vector<long long int> vec;
long long int n, n1, n2, startPoint, k = 0, endPoint, ans = 0, cnt = 0, q = 0,
                                     qry = 0;
long long int nodes, edges;
unordered_map<long long int, long long int> visited;
unordered_map<long long int, list<pair<long long int, long long int>>> adjList;
void show() {
  for (auto x : adjList) {
    cout << x.first << "->";
    for (auto y : x.second) {
      cout << "(" << y.first << "," << y.second << ")";
    }
    cout << endl;
  }
}
long long int dfs(long long int src, long long int par) {
  visited[src] = 1;
  long long int k = 0;
  for (auto x : adjList[src]) {
    if (x.first != par) {
      if (!visited[x.first]) {
        k = max(k, dfs(x.first, src) + x.second);
      }
    }
  }
  return k;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  {
    adjList.clear();
    visited.clear();
    cin >> nodes;
    edges = nodes - 1;
    for (long long int i = 0; i < edges; i++) {
      cin >> startPoint >> endPoint;
      adjList[startPoint].push_back(make_pair(i, k));
      adjList[endPoint].push_back(make_pair(i, k));
      visited[startPoint]++;
      visited[endPoint]++;
      if (cnt < 3 && visited[startPoint] > 1) {
        cnt = visited[startPoint];
        ans = startPoint;
      }
      if (cnt < 3 && visited[endPoint] > 1) {
        cnt = visited[endPoint];
        ans = endPoint;
      }
    }
    cnt = 0;
    vec.resize(nodes + 1, -1);
    for (auto x : adjList[ans]) {
      vec[x.first] = cnt++;
      break;
    }
    for (long long int i = 0; i < nodes - 1; i++) {
      if (vec[i] == -1) {
        cout << cnt++ << endl;
      } else {
        cout << vec[i] << endl;
      }
    }
  }
  return 0;
}
