7. Six students consulted about their grades. The teacher said: A is not the best among the six, B is not the worst among the six, and the six students have different grades. Then the number of different possible rankings of their grades is ( ) .
(A) 120
(B) 216
(C) 384
(D) 504
7. D.

Let $A$ be the set of all possible rankings where A ranks first, and $B$ be the set of all possible rankings where B ranks last. Then
$$
|A|=|B|=5!,|A \cap B|=4!.
$$

The number of all possible rankings where A ranks first or B ranks last is
$$
|A \cup B|=|A|+|B|-|A \cap B|=216.
$$

According to the teacher, the number of all possible rankings of the six students' scores is
$$
6!-216=504
$$