Access to a document is always given using Author and Reader fields.
Create the fields (Check Allow Multiple Values option for the fields) and then include the roles you want in the fields like -
"[A]" : "[B]"
Another method is to write the code in Queryopen to check for the user roles of the currently logged in user and then alert the user if he doesn't contain both roles A and B.
Look for NotesACL class for more info.