How many ways can four math books, three history books, three chemistry books, and two computer science books be arranged on a shelf so that all books of the same subject are together?