Since there are 4 rows, let us label the rows as row 1,2,3,4.
each row has 8 chairs. since all the students of the same class sit in the same row. and no adjacent row is alloted to the same class.
therefore one class can be alloted either in 1 and 3 rows or 2 and 4 rows. therefore there are 2 ways to allot the rows to the class.
now 16 students of this class can be arranged in 16 seats, the number of ways to arrange 16 students in 16 seats=16!
similarly 16 students of other class can be arranged in 16! ways.
therefore total number of ways=2*16!*16! ways