The proceeds of the sale of any animal or conveyance sold pursuant to an order or direction of a magistrate or court made under section 20 , 21 or 22 are to be used (a) firstly, to pay any unpaid monetary penalty imposed by the magistrate or court in respect of an offence under this Act in respect of the animal; and(b) secondly, to pay the costs and expenses connected with selling the animal or conveyance; and(c) thirdly, to pay the costs and expenses connected with taking possession of the animal or conveyance and detaining it; and(d) fourthly, to pay the costs and expenses connected with any veterinary treatment given to the animal; and(e) fifthly, to reimburse the person who owned the animal or conveyance immediately before its sale.