Use brute force first to enumerate all pairs (
a
,
b
) such that
a
A
and
b
B
.