#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
long long dfs(vector<vector<pair<long long, long long> > >& Graph, long long u,
              long long n, vector<bool>& vis,
              vector<pair<long long, long long> >& ans) {
  vis[u] = true;
  long long i, tot = (long long)Graph[u].size(), ans1 = 0;
  for (i = 0; i < tot; i += 1) {
    long long v = Graph[u][i].first;
    if (vis[v]) continue;
    long long temp = dfs(Graph, v, n, vis, ans);
    ans1 += temp;
    ans.push_back(make_pair(temp * (n - temp), Graph[u][i].second));
  }
  return ans1 + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, i;
  cin >> n;
  vector<vector<pair<long long, long long> > > Graph(
      n + 1, vector<pair<long long, long long> >());
  vector<bool> vis(n + 1, false);
  for (i = 0; i < n; i += 1) {
    long long u, v;
    cin >> u >> v;
    Graph[u].push_back(make_pair(v, i));
    Graph[v].push_back(make_pair(u, i));
  }
  vector<pair<long long, long long> > ans;
  long long temp = dfs(Graph, 1, n, vis, ans);
  sort(ans.rbegin(), ans.rend());
  for (i = 0; i < n - 1; i += 1) cout << ans[i].second << endl;
  return 0;
}
