The structure of thin Lie algebras up to the second diamond