(b) for the purpose of determining whether, at a particular time, a person or a partnership is related to another person or partnership, a trust is deemed to be a corporation all the voting shares in the capital stock of whichi. in the case of a testamentary trust under which one or more beneficiaries are entitled to receive all of the income of the trust that arose before the date of death of one or the last surviving of those beneficiaries (in this paragraph referred to as the “distribution date”) and under which no other person can, before the distribution date, receive or otherwise obtain the enjoyment of any of the income or capital of the trust,(1) are owned at that time by such a beneficiary, if that beneficiary’s share of the income or capital of the trust depends on the exercise by any person of, or the failure by any person to exercise, a power to appoint, and if that time occurs before the distribution date, or
(2) are owned at that time by such a beneficiary in a proportion equal to the proportion that the fair market value of the beneficial interest in the trust of the beneficiary is of the fair market value of the beneficial interests in the trust of all the beneficiaries, if subparagraph 1 does not apply and that time occurs before the distribution date,
ii. if a beneficiary’s share of the accumulating income or capital of the trust depends on the exercise by any person of, or the failure by any person to exercise, a power to appoint, are owned at that time by the beneficiary, unless subparagraph i applies and that time occurs before the distribution date,
iii. in any case where subparagraph ii does not apply, are owned at that time by the beneficiary in a proportion equal to the proportion that the fair market value of the beneficial interest in the trust of the beneficiary is of the fair market value of all beneficial interests in the trust, unless subparagraph i applies and that time occurs before the distribution date, and
iv. in the case of a trust referred to in section 467, are owned at that time by the person referred to in that section from whom property of the trust or property for which property of the trust was substituted was directly or indirectly received.