The tax imposed by paragraph (1) shall apply in the case of any trust which is exempt, except as provided in this part or part II (relating to private foundations), from taxation under this subtitle by reason of section
501
(a) and which, if it were not for such exemption, would be subject to subchapter J (sec.
641 and following, relating to estates, trusts, beneficiaries, and decedents).