Using SQL ORDER BY for complex criteria
You only need a CASE expression in the ORDER BY, to divide the rows into two groups, so the ones with class 'A' or 'B' are put in first group (1) and the all the others in the second (2):

ORDER BY 
    CASE WHEN class IN ('A', 'B') THEN 1 ELSE 2 END,
    rank ;