#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, m, n;
  while (cin >> n) {
    int x[n - 1], y[n - 1];
    for (i = 0; i < n - 1; i++) cin >> x[i] >> y[i];
    l = 1;
    for (i = 0; i < n - 1; i++) {
      if ((x[i] == 1 && y[i] == 2) || (y[i] == 1 && x[i] == 2))
        cout << "0" << endl;
      else {
        cout << l << endl;
        l++;
      }
    }
  }
  return 0;
}
