import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    int n = scan!int;
    Node[] nodes;
    foreach(i; 0 .. n) nodes ~= new Node(i);

    Edge[] edges;
    foreach(i; 0 .. n - 1){
        edges ~= new Edge(i, nodes[scan!int - 1], nodes[scan!int - 1]);
    }

    Node nd0;
    foreach(nd; nodes) if(nd.edges.length >= 3) nd0 = nd;

    int v = 0;
    if(nd0){
        nd0.edges[0].value = 0;
        nd0.edges[1].value = 1;
        nd0.edges[2].value = 2;
        v += 3;
    }

    foreach(ed; edges) if(ed.value < 0) ed.value = v, v += 1;

    foreach(ed; edges) ed.value.print;

}

class Edge{
    int id;
    Node a, b;
    int value = -1;
    this(int id, Node a, Node b){
        this.id = id;
        this.a = a, this.b = b;
        a.edges ~= this, b.edges ~= this;
    }
}
class Node{
    int id;
    Edge[] edges;
    this(int id){
        this.id = id;
    }
}
