Draw the class diagram for the following classes.
Represent each class and its inheritance, aggregation, composition, or association relationships as canonical Mermaid class-diagram lines. Implement build_class_diagram(classes, relationships), returning isolated class declarations followed by sorted relationship declarations.
Classes are strings. Each relationship is a dictionary with from, to, and type, where type is inheritance, aggregation, composition, or association. Use Mermaid syntax such as Child --|> Parent and return a list of strings.
def build_class_diagram(classes, relationships):