nor (B) dividends described in subparagraph (B) of such section (determined without regard to section 245(a)(12)). (4) Treatment of distributions from earnings before 1987 (A) In general In the case of any dividend paid out of earnings and profits of the specified 10-percent owned foreign corporation (computed in accordance with sections 964(a) and 986) accumulated in taxable years beginning before January 1, 1987— (i) paragraphs (1), (2), and (3) shall be applied without regard to the phrase post-1986 each place it appears, and (ii) paragraph (2) shall be applied by substituting after the date specified in section 316(a)(1) for in taxable years beginning after December 31, 1986 . (B) Dividends paid first out of post-1986 earnings Dividends shall be treated as paid out of post-1986 undistributed earnings to the extent thereof. (5) Treatment of certain dividends in excess of undistributed earnings In the case of any dividend from the specified 10-percent owned foreign corporation which is in excess of undistributed earnings (as determined under paragraph (2) after taking into account the modifications described in clauses (i) and (ii) of paragraph (4)(A)), the foreign-source portion of such dividend is an amount which bears the same ratio to such dividend as— (A) the portion of the earnings and profits described in subparagraph (B) which is attributable to neither income described in paragraph (3)(A) nor dividends described in paragraph (3)(B), bears to (B) the earnings and profits of such corporation for the taxable year in which such distribution is made (computed as of the close of the taxable year without diminution by reason of any distributions made during the taxable year). (d) Disallowance of foreign tax credit, etc (1) In general No credit shall be allowed under section 901 for any taxes paid or accrued (or treated as paid or accrued) with respect to any dividend for which a deduction is allowed under this section. (2) Denial of deduction No deduction shall be allowed under this chapter for any tax for