Stacking context and paint order

In the following, 'AA' should overflow and be painted over the 'B' boxes.

A
AA
B
A
AA
B

In the following, 'B' boxes should be painted over the overflowing 'AA' text.

A
AA
B
A
AA
B
A
AA
B
A
AA
B