If any railroad corporation required by law to pay the costs of surveying, selecting, or conveying any lands granted to such company or for its use and benefit by Act of Congress shall for thirty days neglect or refuse to pay any such costs after demand for payment thereof by the Secretary of the Interior, he shall notify the Attorney General, who shall at once commence proceedings to collect the same. But when any sum shall be collected of such railroad company as costs of surveying, selecting, and conveying any tract of land which shall have been purchased under the provisions of section
882 of this title, the Secretary of the Interior shall out of such collections reimburse said purchaser, his heirs or assigns, the amount of money paid by him as the costs of such surveying, selecting, and conveying.