I'm going to make the assumption that X/XN is available on each flight, and gloss over the whole availability part. Are C and D in different countries? If yes, the 24 hour layover rule applies to that segment. I believe there are also situations in which overnight domestic layovers allow for more lenient rules than the standard 4 hours, but I don't know the specifics of those rules.