(ii) in the case of a child (as so defined) of an individual entitled to an old-age insurance benefit or to a disability insurance benefit, the first month throughout which such child is a child (as so defined) and meets the criteria specified in subparagraphs (B) and (C) (if in such month he meets the criterion specified in subparagraph (A)),
whichever is earlier, and ending with the month preceding whichever of the following first occurs—
(D) the month in which such child dies, or marries,
(E) the month in which such child attains the age of 18, but only if he (i) is not under a disability (as so defined) at the time he attains such age, and (ii) is not a full-time elementary or secondary school student during any part of such month,
(F) if such child was not under a disability (as so defined) at the time he attained the age of 18, the earlier of— (i) the first month during no part of which he is a full-time elementary or secondary school student, or (ii) the month in which he attains the age of 19, but only if he was not under a disability (as so defined) in such earlier month;
(G) if such child was under a disability (as so defined) at the time he attained the age of 18 or if he was not under a disability (as so defined) at such time but was under a disability (as so defined) at or prior to the time he attained (or would attain) the age of 22— (i) the termination month, subject to section 423(e) of this title (and for purposes of this subparagraph, the termination month for any individual shall be the third month following the month in which his disability ceases; except that, in the case of an individual who has a period of trial work which ends as determined by application of section 422(c)(4)(A) of this title , the termination month shall be the earlier of (I) the third month following the earliest month after the end of such period of trial work with respect to which such individual is determined to no longer be suffering from a disabling physical or mental impairment, or (II) the third month following the earliest month in which such individual engages or is determined able to engage in substantial gainful activity, but in no event earlier than the first month occurring after the 36 months following such period of trial work in which he engages or is determined able to engage in substantial gainful activity), or (if later) the earlier of— (ii) the first month during no part of which he is a full-time elementary or secondary school student, or (iii) the month in which he attains the age of 19, but only if he was not under a disability (as so defined) in such earlier month; or
(H) if the benefits under this subsection are based on the wages and self-employment income of a stepparent who is subsequently divorced from such child’s natural parent, the month after the month in which such divorce becomes final.
Entitlement of any child to benefits under this subsection on the basis of the wages and self-employment income of an individual entitled to disability insurance benefits shall also end with the month before the first month for which such individual is not entitled to such benefits unless such individual is, for such later month, entitled to old-age insurance benefits or unless he dies in such month. No payment under this paragraph may be made to a child who would not meet the definition of disability in section 423(d) of this title except for paragraph (1)(B) thereof for any month in which he engages in substantial gainful activity.