How to hide node by Role similar to the Hide Block by Role module?
Rules (the module) is your friend ... Here is a prototype of a rule (in Rules export format) that you could use (assuming that the Role ID (rid) for Role B is "4", adapt the value of this rid to fit your case):

{ "rules_limit_access_to_some_urls" : {
    "LABEL" : "Limit access to some URLs",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "NOT user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "4" : "4" } }
        }
      },
      { "data_is" : {
          "data" : [ "site:current-page:path" ],
          "op" : "IN",
          "value" : { "value" : [
              "node\/123",
              "node\/456"
            ]
          }
        }
      }
    ],
    "DO" : [
      { "redirect" : { "url" : "access_denied" } },
      { "drupal_message" : {
          "message" : "Access to the content located at \u0022\u003Cstrong\u003E[site:current-page:path]\u003C\/strong\u003E\u0022 is not allowed.",
          "type" : "warning"
        }
      }
    ]
  }
}


After you enable the above rule, you can grant Access (view) permission to the nodes "node/123" and "node/456" for users with role A (using the Content Access module). That will already prevent access to these nodes for any user who does not have that role A. 

The above rule will ensure that users who do not have role B, will NOT be able to actually "view" these nodes. Instead they'll get a message starting with "Access to the content located at ..." (change this message to whatever fits).