Recommendation Letter: How to properly mention the grade and the rank of a student in multiple courses?
X attended with me class A (grade A), class B (grade B), [...] and class
E (grade E).

Or your preferred variation of the above. However, you can also repeat the grade statement several times, possibly adding for each class details about the student's participation.