Mechanism of polycondensation of polyimides