Menu editor works based on ‘AND’ condition on restriction. For example if Role A denies Menu A and Role B denies Menu B, a user who have roles A & B the result will be ‘deny A AND deny B’. You can remove the deny condition on Menu B by enabling the ‘Disable For Secondary Role’ option for Role B, provided Role B is a secondary role for that user. Basically only the primary role rules will be applied when that option is enabled.
In your case even if you enable that option for Role B, user will only have X & Y, since Role A explicitly denies menu Z. Your best option is to create a third role for User AB.