; (III) the Secretary transfers custody of the alien pursuant to law to another Federal agency or a State or local government agency in connection with the official duties of such agency; or (IV) a court or the Board of Immigration Appeals orders a remand to an immigration judge or the Board of Immigration Appeals, during the time period when the case is pending a decision on remand (with the removal period beginning anew on the date that the alien is ordered removed on remand). (ii) Renewal If the removal period has been extended under subparagraph (C)(i), a new removal period shall be deemed to have begun on the date— (I) the alien makes all reasonable efforts to comply with the removal order, or to fully cooperate with the Secretary’s efforts to establish the alien’s identity and carry out the removal order; (II) the stay of removal is no longer in effect; or (III) the alien is returned to the custody of the Secretary. (iii) Mandatory detention for certain aliens In the case of an alien described in subparagraphs (A) through (D) of section 236(c)(1), the Secretary shall keep that alien in detention during the extended period described in clause (i). (iv) Sole form of relief An alien may seek relief from detention under this subparagraph only by filing an application for a writ of habeas corpus in accordance with chapter 153 of title 28, United States Code. No alien whose period of detention is extended under this subparagraph shall have the right to seek release on bond. ; (4) in paragraph (3)— (A) by adding after If the alien does not leave or is not removed within the removal period the following: or is not detained pursuant to paragraph (6) of this subsection ; and (B) by striking subparagraph (D) and inserting the following: (D) to obey reasonable restrictions on the alien’s conduct or activities that the Secretary prescribes for the alien, in order to prevent the alien from absconding, for the protection of the community, or for other purposes related to the enforcement of the immigration laws.