Be sure to allow for the case where every pair (x, y) in A and every pair (y, z) in B have the same y value.